【发布时间】:2013-08-09 14:08:01
【问题描述】:
我想知道包含文件的无限循环是否会导致编译器问题或链接器问题。 我试过这个:
/* file : try.c */
#include "try1.c"
int main(void) {}
/* file : try1.c */
#include "try.c"
int a(void) { return 0; }
编译命令是:
gcc -Wall try.c -o try
这显然会导致很长的输出(像这样开始):
try.c:5:1: error: expected '=', ',', ';', 'asm' or '__attribute__' before '{' token
In file included from try.c:1:0,
from try1.c:1,
from try.c:1:
try1.c:4:1: error: expected '=', ',', ';', 'asm' or '__attribute__' before '{' token
In file included from try1.c:1:0,
from try.c:1:
try.c:5:1: error: expected '=', ',', ';', 'asm' or '__attribute__' before '{' token
In file included from try.c:1:0:
try1.c:4:1: error: expected '=', ',', ';', 'asm' or '__attribute__' before '{' token
try.c:5:1: error: expected '=', ',', ';', 'asm' or '__attribute__' before '{' token
In file included from try.c:2:0,
from try1.c:1,
from try.c:1,
from try1.c:1,
from try.c:1,
from try1.c:1,
from try.c:1,
from try1.c:1,
from try.c:1,
from try1.c:1,
.
.
etc...
嗯,显然这里有一个无限循环。但它什么时候发生?在编译过程或链接器一个?我想你会在编译过程中告诉我,因为它将在这里定义多个具有相同名称的函数(因为循环),但不是在链接器进程中发生联合文件的部分(然后有只有一个文件没有编译问题)?
谢谢!
【问题讨论】:
-
这就是 .h 文件的用途。我们通常不会
#include.c 文件。 -
我知道。但是您也可以包含 .c 文件,我不想在此消息中添加 4 个文件(2 个 .h 和 2 个 .c)。只是想让事情变得更简短。
标签: c loops compiler-construction linker