0

この奇妙な状況が続いています。raspberry pi c ライブラリ関数の一部のプレフィックスを解除しようとしています。たとえば、bcm2835_delay() を delay() にしたい。pi.h と pi.c の 2 つのファイルがあります。2 つをプレフィックスを外してコンパイルするとgcc -lm pi.c -c、delay() は bcm2835_delay() になります。以下は、私の 2 つのファイルと の出力ですobjdump -t pi.o

pi.h

#include <bcm2835.h>

#define PIN05 RPI_V2_GPIO_P1_05
#define PIN07 RPI_V2_GPIO_P1_07
#define PIN08 RPI_V2_GPIO_P1_08
#define PIN10 RPI_V2_GPIO_P1_10
#define PIN11 RPI_V2_GPIO_P1_11
#define PIN12 RPI_V2_GPIO_P1_12
#define PIN13 RPI_V2_GPIO_P1_13
#define PIN15 RPI_V2_GPIO_P1_15
#define PIN16 RPI_V2_GPIO_P1_16
#define PIN18 RPI_V2_GPIO_P1_18
#define PIN19 RPI_V2_GPIO_P1_19
#define PIN21 RPI_V2_GPIO_P1_21
#define PIN22 RPI_V2_GPIO_P1_22
#define PIN23 RPI_V2_GPIO_P1_23
#define PIN24 RPI_V2_GPIO_P1_24
#define PIN26 RPI_V2_GPIO_P1_26

#define INPUT BCM2835_GPIO_FSEL_INPT
#define OUTPUT BCM2835_GPIO_FSEL_OUTP

// rename the delay function given already
void delay(unsigned int millis);

// rename the microsecond delay function
void delay_micro(uint64_t micros);

// set the pinout to low, check that the pin is output
void set_low(uint8_t pin);

// ease the input setting
void set_input(uint8_t pin);

// ease the output setting
void set_output(uint8_t pin);

と pic.c

#include <bcm2835.h>
#include "pi.h"

// rename the delay function given already
void delay(unsigned int millis) {
  bcm2835_delay(millis);
}

// rename the microsecond delay function
void delay_micro(uint64_t micros) {
  bcm2835_delayMicroseconds(micros);
}

// set the pinout to low, check that the pin is output
void set_low(uint8_t pin) {

}

// ease the input setting
void set_input(uint8_t pin) {
  bcm2835_gpio_fsel(pin, INPUT);
}

// ease the output setting
void set_output(uint8_t pin) {
  bcm2835_gpio_fsel(pin, OUTPUT);
}

出力

pi.o: ファイル形式 elf32-littlearm

SYMBOL TABLE:
00000000 l    df *ABS*  00000000 pi.c
00000000 l    d  .text  00000000 .text
00000000 l    d  .data  00000000 .data
00000000 l    d  .bss 00000000 .bss
00000000 l    d  .note.GNU-stack  00000000 .note.GNU-stack
00000000 l    d  .comment 00000000 .comment
00000000 l    d  .ARM.attributes  00000000 .ARM.attributes
00000000 g     F .text  00000020 bcm2835_delay
00000020 g     F .text  00000020 delay_micro
00000000         *UND*  00000000 bcm2835_delayMicroseconds
00000040 g     F .text  00000020 set_low
00000060 g     F .text  0000002c set_input
00000000         *UND*  00000000 bcm2835_gpio_fsel
0000008c g     F .text  0000002c set_output

ここで、delay() 関数を除いて、すべての関数定義が問題なくシンボル テーブルに作成されていることがわかります。シンボル テーブルでは、bcm2835_delay として表示されます。delay() を my_delay() に変更すると、シンボル テーブルに my_delay() として問題なく作成されます。ここで何が起こっているのですか?

4

1 に答える 1

0

コンパイラは関数をインライン関数として扱っていました。

于 2014-03-05T09:37:59.990 に答える