Why does declaring main as an array compile?

前端 未结 6 1938
一整个雨季
一整个雨季 2021-01-31 07:35

I saw a snippet of code on CodeGolf that\'s intended as a compiler bomb, where main is declared as a huge array. I tried the following (non-bomb) version:



        
6条回答
  •  一整个雨季
    2021-01-31 07:55

    It only compiles because you don't use the proper options (and works because linkers sometimes only care for the names of symbols, not their type).

    $ gcc -std=c89 -pedantic -Wall x.c
    x.c:1:5: warning: ISO C forbids zero-size array ‘main’ [-Wpedantic]
     int main[0];
         ^
    x.c:1:5: warning: ‘main’ is usually a function [-Wmain]
    

提交回复
热议问题