gpt4 book ai didi

c - 使用 stdlib.h 或 stdio.h 中的某些函数会导致语法错误

转载 作者:太空狗 更新时间:2023-10-29 15:53:37 27 4
gpt4 key购买 nike

我正在 Win7 Pro x64 上的 Visual Studio 2005 中编写一些 C 代码。代码正确;它在 Eclipse 下的 MinGW 上编译和运行。但是,在 VS2005 中构建代码时,使用标准 C 库(如 stdio 或 stdlib)中的某些函数会导致以下行显示语法错误。例如:

#include<time.h>
#include<stdlib.h>
#include<stdio.h>
#include"someOtherHeader.h"

int main(void){
srand((unsigned int) time(NULL));
double start;
.
.
.

以下代码无关紧要。 VS2005 说缺少';'在“类型”之前。注释掉 srand() 可以解决问题。奇怪的是,后面调用rand()的时候,就没有问题了。我还注意到 exit() 和 fprint() 的行为。但不适用于 malloc()。想法?

最佳答案

在 Visual Studio 中使用 C 会使编译器进入严格(旧式 C)模式。您的所有声明都必须位于 block 的开头:

#include<time.h>
#include<stdlib.h>
#include<stdio.h>
#include"someOtherHeader.h"

int main(void){
double start;
srand((unsigned int) time(NULL));
.
.
}

关于c - 使用 stdlib.h 或 stdio.h 中的某些函数会导致语法错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3409299/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com