开发者

Using certain functions from stdlib.h or stdio.h causes syntax errors

开发者 https://www.devze.com 2023-01-10 18:30 出处:网络
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 s

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;
.
.
.
开发者_C百科

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?


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));
    .
    .
}


Visual Studio supports NOT C99 (just a little bit)

0

精彩评论

暂无评论...
验证码 换一张
取 消