I get this code:
#include<stdio.h>
#include<stdlib.h>
void main(void)
{
char *ptr = (char*)malloc(10);
if(NULL == ptr)
{
printf("\n Malloc failed \n");
return;
}
else
{
// Do some processing
free(ptr);
}
return;
}
在Visual C中编译成功,但在gcc中无法编译,我收到了“错误:'main'必须返回'int'”的消息。那么main()函数的返回类型'int'是一种约定(由编译器定义),还是C语言的规则呢?
main()
函数的返回类型应该是实现告诉你要使用的类型。即使是在 comp.lang.c 上的 Ansi-C 硬核人士也应该知道这一点... - This isn't my real name