【发布时间】:2011-11-11 06:29:25
【问题描述】:
请任何人详细说明这些错误:-
void main()
{
int a=5, b=60, func();
printf("\nI am in main-1");
int func(){
printf("\nI am in funct");
return 1;
}
func();
printf("\nI am in main-2");
}
我得到的错误是:
- 在函数“main”中:
- 第 8 行:错误:“func”的静态声明遵循非静态 声明
- 第 4 行:错误:'func' 的先前声明在这里
- 第 3 行:警告:'main' 的返回类型不是 'int'
我认为 C 允许嵌套类,因为以下代码运行良好:
void outerfunc()
{
int func()
{
printf("\nI am in funct");
return 1;
}
func();
}
void main()
{
printf("\nI am in main-1");
outerfunc();
printf("\nI am in main-2");
}
【问题讨论】:
-
void mainARRRRRRRRGGGGGGGGHHHHHHHH! -
另外,
main()在 C 中返回int。 -
这表明你不是在看书,而是一本好书。
The Definitive C Book Guide and List- stackoverflow.com/questions/562303/… -
@pmg:我一直想知道为什么人们会对
void main()如此烦恼。 C 标准并没有禁止它。 -
@OP -
I think C allows nested class because the following code is working fine- 别想了,开始读哥们:-) - stackoverflow.com/questions/2608158/nested-function-in-c
标签: c gcc nested-function