【发布时间】:2013-02-01 03:25:39
【问题描述】:
我在文件“draw.h”中有一个函数:
void TileSystem() {
// Some code here.
}
在“main.c”文件中,我称之为它,因为我在文件中#included“draw.h”。功能很好用!!
然后,我决定将函数重命名为
void CreateTileSystem() {
// Some code here.
}
我得到以下输出:
gcc main.c -std=c99 -o main `pkg-config --cflags --libs allegro-5.0 allegro_acodec-5.0 allegro_audio-5.0 allegro_color-5.0 allegro_dialog-5.0 allegro_font-5.0 allegro_image-5.0 allegro_main-5.0 allegro_memfile-5.0 allegro_physfs-5.0 allegro_primitives-5.0 allegro_ttf-5.0`
main.c: In function ‘main’:
main.c:217:12: warning: implicit declaration of function ‘CreateTileSystem’ [-Wimplicit-function-declaration]
/tmp/cclNEg6q.o: In function `main':
main.c:(.text+0xb1e): undefined reference to `CreateTileSystem'
collect2: error: ld returned 1 exit status
make: *** [main] Error 1
然后,我只是将它重命名回 TileSystem 并且运行良好。我在整个代码中没有其他引用。这根本没有意义!我想重命名,以便在函数中使用动词(我认为这是一个更“正确”的标准)。好吧,我真的很想知道会发生什么。我真的找不到错误,而且当我重命名它时,它又恢复了工作,这让我更加沮丧。
非常感谢!
【问题讨论】:
-
你不应该在头文件中添加函数体,只添加签名,并将函数体放在单独的 c/cpp 文件中。
-
我以这种方式调用 TileSystem();,并且可以工作。然后,我这样调用CreateTileSystem();,还是不行。
-
问题可能出在 THE NAME 上?我不知道,可能是一些随机内存问题......但我得到了相同的结果,将函数更改为 int 或 float 等。
-
我的猜测是 main.c 中有一个重新声明的 TileSystem 正在生效。生成预处理文件以查看编译器看到的内容。
标签: c declaration implicit