有人可以解释我为什么以下code编译并没有警告或错误?
我希望编译器警告我说,功能测试不希望任何参数。但是,code编译并运行递归功能测试。
的#include<&stdio.h中GT;#包括LT&;&stdlib.h中GT;静态无效TEST1(INT A,INT B,INT C){}静态无效测试(){ 的printf(在这里\\ n); 测试(1,2,3);}无效的主要(){ 测试();}解决方案
在C ++中,无效测试()声明了一个函数,它没有paramerers(并且没有返回)。
在C,无效测试()声明了一个函数,它的参数未指定的(但不是变量)数量(并且没有返回)。因此,所有呼叫都有效(按原型)的温度。
在C,使用无效测试(无效)。
Can somebody explain to me why the following code does compile without a warning or error ?
I would expect the compiler to warn me that the function test doesn't expect any arguments. But the code compiles and runs function test recursively.
#include <stdio.h> #include <stdlib.h> static void test1(int a, int b, int c) {} static void test() { printf("HERE\n"); test(1,2,3); } void main() { test(); }解决方案
In C++, void test() declares a function that takes no paramerers (and returns nothing).
In C, void test() declares a function that takes an unspecified (but not variable) number of parameters (and returns nothing). So all your calls are valid (according to the prototype) in C.
In C, use void test(void).
更多推荐
不带参数的行为C函数
发布评论