VS2005编译C语言程序

来源:互联网 发布:unity3d 5.0教程 编辑:程序博客网 时间:2024/04/28 07:13

用VS2005编译如下代码:

void main()

{

printf("Hello World!");
int a;

scanf("%d",&a);

这样会报错:error C2143: syntax error : missing ';' before 'type'

vs2005和eclipse的区别在于eclipse可以通过。


void main()
{
int a;
printf("Hello World!");

scanf("%d",&a);

只要把int a; 放到第一行就可以编译通过了。


网上查了下,原因如下:

"microsoft C compiler wants all variables declared at top of function",

This is what C89 defines. C99 allows variable declarations also in the middle of a function.

The problem is you are using a C file. This means the compiler implements strict C rules. If you change your source file to a cpp type file, you will use the C++ compiler which is myuch more flexible