C中参数的默认数据类型?
我是C新手,有一个问题。我想我犯了一个错误,但是编译器没有发出警告,程序运行正常 我认为第4行有一个错误:C中参数的默认数据类型?,c,gcc,C,Gcc,我是C新手,有一个问题。我想我犯了一个错误,但是编译器没有发出警告,程序运行正常 我认为第4行有一个错误: #include <stdio.h> void void_int(int x); void void_int(x) { // <-- no type definition for parameter x printf( "void_int: %d\n", x); } int main(int argc, char **argv) { p
#include <stdio.h>
void void_int(int x);
void void_int(x) { // <-- no type definition for parameter x
printf( "void_int: %d\n", x);
}
int main(int argc, char **argv) {
printf("Hello world\n");
// declare a function pointer
void (*by_ref_void_int)(int);
// assign pointer to a function
by_ref_void_int = &void_int;
// run referenced function
by_ref_void_int(2);
return 0;
}
为了保持与arcaic版本的
C
语言的兼容性,如果声明未指定类型,则默认类型假定为int
如果您只是指定语言的一个版本,编译器肯定会帮助您发现这一点
gcc -std=c99 a.c
a.c: In function ‘void_int’:
a.c:4:6: warning: type of ‘x’ defaults to ‘int’ [enabled by default]
void void_int(x) { // <-- no type definition for parameter x
^
gcc-std=c99交流电
a、 c:在函数“void_int”中:
a、 c:4:6:警告:“x”的类型默认为“int”[默认启用]
void\u int(x){//谢谢,这很有帮助。你知道哪种标准适合便携式程序吗?@Spliffster可能C99
,在linux、mac和bsd下对它有很好的支持,windows仍在努力追赶(是的,这是1999年和windows(Visual Studio,windows的IDE参考)的标准)在windows上,您可以期待C99的部分支持,通常这就足够了。
gcc -std=c99 a.c
a.c: In function ‘void_int’:
a.c:4:6: warning: type of ‘x’ defaults to ‘int’ [enabled by default]
void void_int(x) { // <-- no type definition for parameter x
^