![](/img/trans.png)
[英]Why does the below recursive main function start with the value 1 as parameter?
[英]C: defining function below main - why does this compile?
struct ack {
char a, b, c;
};
main()
{
struct ack bad;
foo(bad);
}
foo(c)
struct ack c;
{
}
這是gcc中的測試用例。 當我嘗試使用gcc4.8進行編譯時,它可以毫無問題地進行編譯。 但是,我了解到必須在main之前聲明函數。 為什么還要編譯?
嘗試編譯
-std=c11 -pedantic-errors
您將獲得所需的診斷信息。
默認情況下, gcc
使用-std=gnu89
進行編譯,這是c89 + GNU擴展。 隱式聲明的c89規則已在c99中刪除。
當前,通常,當編譯器在main()
找到對foo(bad)
的調用並且未定義foo時,編譯器會假定它存在並且將返回int
。
這將問題推給鏈接器,如果在源文件的某個位置未定義foo()
,鏈接器將抱怨。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.