问题
I'm working on some C code in Visual Studio 2005 on Win7 Pro x64. The code is correct; it compiles and runs on MinGW under Eclipse. However, using certain functions from the standard C libraries like stdio or stdlib causes the following lines to exhibit syntax errors when the code is built in VS2005. As an example:
#include<time.h>
#include<stdlib.h>
#include<stdio.h>
#include"someOtherHeader.h"
int main(void){
srand((unsigned int) time(NULL));
double start;
.
.
.
The following code doesn't matter. VS2005 says that there is a missing ';' before 'type'. Commenting out srand() fixes the problem. Oddly, when rand() is called later, there is no problem. I also noticed the behavior with exit() and fprint(). But not with malloc(). Thoughts?
回答1:
Using C in Visual Studio puts the compiler into strict (old school C) mode. All your declarations have to be at the beginning of your blocks:
#include<time.h>
#include<stdlib.h>
#include<stdio.h>
#include"someOtherHeader.h"
int main(void){
double start;
srand((unsigned int) time(NULL));
.
.
}
回答2:
Visual Studio supports NOT C99 (just a little bit)
来源:https://stackoverflow.com/questions/3409299/using-certain-functions-from-stdlib-h-or-stdio-h-causes-syntax-errors