没有定义的函数参数的默认值类型为int?我是疯了吗? [英] No defined type of a function parameter defaults to int? Am I insane?
问题描述
对于一些奇怪的原因,我是在复制其不使用的类型,忘了添加一个到一个函数定义参数的另一种语言的例子,它的工作。
For some odd reason I was copying an example in another language of which does not use types, and forgot to add one in to a function definition parameter, and it worked.
#include <stdio.h>
char toChar(n) {
//sizeof n is 4 on my 32 bit system
const char *alpha = "0123456789ABCDEF";
return alpha[n];
}
int main() {
putchar(toChar(15)); //i.e.
return 0;
}
我相信主默认是通过一些标准(但只返回)的大多数编译器诠释,这是也是一个行为的其他功能也同样如此或定义此实现?这似乎只是与众不同,我的编译器只是一个稍微过时的GCC端口(MinGW的)。
I am sure that main defaults to int by most compilers of some standard (but only return), is this also a behaviour true for other functions as well or is this implementation defined? It seems just out of the ordinary, my compiler is just a slightly outdated GCC port (MinGW).
推荐答案
K&安培; R风格的函数声明:
K&R-style function declaration:
void foo(n)
int n;
{
}
如果没有指定类型,则默认为int。这是有效的C89,C99没有
If type isn't specified, it defaults to int. This is valid in C89, not C99
这篇关于没有定义的函数参数的默认值类型为int?我是疯了吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!