ファイルをインクルードする無限ループが原因でコンパイラの問題が発生するのか、それともリンカの問題が発生するのか疑問に思っています。私はこれを試しました:
/* 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...
まあ、明らかにここには無限ループがあります。しかし、いつ発生しますか?コンパイルプロセスまたはリンカープロセスで?ここで同じ名前の複数の関数を定義するため(ループのため)、コンパイルプロセスで教えてくれると思いますが、リンカープロセスでファイルを結合する部分ではありません(そして、 1 つのファイルのみの場合、コンパイルに問題はありません) ?
ありがとう !