Weird compilation error in Visual Studio 2008

2019-01-26 18:56发布

I have a problem compiling the following code:

#include <stdio.h>
#include <limits.h>
int main () {
    printf("short: [%d,%d]\n",SHRT_MIN,SHRT_MAX);
    printf("int: [%d, %d]\n",INT_MIN, INT_MAX);
    printf("long: [%d, %d]\n",LONG_MIN,LONG_MAX);
    int aa=017;
    printf("%d\n",aa);
    return 0;
}

Error message is:

1>c:\tic\ex1\ex2\ex2.c(12) : error C2143: syntax error : missing ';' before 'type'
1>c:\tic\ex1\ex2\ex2.c(13) : error C2065: 'aa' : undeclared identifier

However, compilation for this is fine:

    #include <stdio.h>
    #include <limits.h>
    int main () {
        int aa=017;
        printf("short: [%d,%d]\n",SHRT_MIN,SHRT_MAX);
        printf("int: [%d, %d]\n",INT_MIN, INT_MAX);
        printf("long: [%d, %d]\n",LONG_MIN,LONG_MAX);
        printf("%d\n",aa);
        return 0;
    }

Any idea what the issue is?

7条回答
不美不萌又怎样
2楼-- · 2019-01-26 19:42

Visual Studio doesn't support C99 so all declarations (such as for aa in your example) in a block must appear before any statements (such as your printf calls).

查看更多
登录 后发表回答