這個程序違背了我在C中學過和學過的所有東西。這是如何編譯的?爲什麼這不需要是int main?爲什麼不能返回0?你不需要在main之上初始聲明sub()嗎?這使我感到厭惡。我喜歡把我的功能放在主要位置。程序編譯有錯誤
#include <stdio.h>
main()
{
sub();
sub();
}
sub()
{
static int y = 5;
printf(" y is %d \n",y);
y++;
}
的gcc版本是:
gcc version 4.4.7 20120313 (Red Hat 4.4.7-11) (GCC)
這是一個老版本好像而不是瘋狂的老。
https://www.gnu.org/software/gcc/releases.html
如何檢查,如果這是C90或C89?
所有這些關於「C標準如何允許這樣做」的gcc問題令人討厭...... **如果不用'gcc -std = c11 -pedantic-errors'進行編譯,那麼gcc不是嚴格的符合C編譯器**,但是是一個非標準的編譯器,它針對大量奇怪的GNU擴展進行編譯。 – Lundin 2014-12-05 07:45:09
在編譯之前先啓用所有的警告http://stackoverflow.com/questions/26488502/which-section-in-c89-standard-allows-the-implicit-int-rule http://stackoverflow.com/questions/8440816/警告隱式聲明的功能http://stackoverflow.com/questions/8220463/c-function-calls-understanding-the-implicit-int-rule – 2014-12-05 10:05:24
@Lundin我應該使用這個,而不是'gcc -std = c90 -pedantic-errors'?維基百科使得它聽起來像c11不支持,直到gcc版本4.6。 http://en.wikipedia.org/wiki/C11_%28C_standard_revision%29我已經提供了我使用的版本。 – cokedude 2014-12-06 00:26:19