为什么"int main(anything_you_type)"不会产生任何错误?

Jee*_*tel 9 c compiler-construction error-handling gcc program-entry-point

在这里,我已经在主要参数声明中写了我的名字,但是这个程序仍然有效并且没有给出任何警告.

#include <stdio.h>
int main(Mr32) 
{
    printf("why this works?");
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

每当我写任何东西代替mr32时,代码仍然有效.我真的不知道为什么会这样.根据C编程标准,这是错误的,对吧?

编辑: 我已经尝试过 - 但它没有发出任何警告.

我认为这应该是错误,因为我没有做标准的C函数定义声明

在c中,每个函数定义都必须遵循此格式

return-type function_name ( arg_type arg1, ..., arg_type argN ); 
Run Code Online (Sandbox Code Playgroud)

这也应该适用于main()吧.. ??

好的-Wextra显示警告mr32默认为int.

那么为什么main()中的任何参数的默认类型都是int?

Mat*_*teo 8

在K&R C定义中,没有类型的参数默认为int.然后你的代码对应

int main( int Mr32 ) {
    printf("why this works?");
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

看看这个答案的详细信息:C函数语法,参数列表后声明的参数类型

更新

总结一下:在C89中,仍然支持K&R声明

注意

虽然这是支持我永远不会使用它:代码应该是可读的