【发布时间】:2014-03-16 18:57:10
【问题描述】:
我发现here如果函数在函数调用之下,函数原型在函数调用之前是必需的。
我在 gcc 编译器中检查了这个案例,它编译的代码没有函数原型。
例子:
#include <stdio.h>
//int sum (int, int); -- it runs with this commented line
int main (void)
{
int total;
total = sum (2, 3);
printf ("Total is %d\n", total);
return 0;
}
int sum (int a, int b)
{
return a + b;
}
能解释一下这个问题吗?
【问题讨论】:
-
听起来像是 C99 更新
-
我个人认为避免此类问题的最佳方法是使用“-Wpedantic -ansi”选项编译代码。这样,您的代码甚至无法编译,因为“//”无法识别。 :)
标签: c function-prototypes