使用某些功能stdlib.h中或stdio.h中导致语法错误 [英] Using certain functions from stdlib.h or stdio.h causes syntax errors

查看:357
本文介绍了使用某些功能stdlib.h中或stdio.h中导致语法错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我工作在Visual Studio 2005中的一些C code对Win7的临64。在code是正确的;它编译和Eclipse下运行的MinGW的。但是,使用某些功能标准C库,例如标准输入输出或STDLIB导致以下线路时的code是建立在VS2005表现出语法错误。作为一个例子:

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

以下code无所谓。 VS2005说,有一个缺少;前类型。注释掉srand()函数解决了这个问题。奇怪的是,当兰特()是后来被称为,是没有问题的。我还注意到,退出()和fprint()的行为。但不是使用malloc()。思考?

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?

推荐答案

在Visual Studio中使用C却将编译成严格的(老同学C)模式。您的所有声明都在你块的开头:

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

这篇关于使用某些功能stdlib.h中或stdio.h中导致语法错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆