Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/c/71.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/visual-studio/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
文件赢得';不能在MS Visual Studio中编译,但将在GCC中编译。为什么?_C_Visual Studio_Gcc_C89 - Fatal编程技术网

文件赢得';不能在MS Visual Studio中编译,但将在GCC中编译。为什么?

文件赢得';不能在MS Visual Studio中编译,但将在GCC中编译。为什么?,c,visual-studio,gcc,c89,C,Visual Studio,Gcc,C89,我编写了这样的示例代码: #include <stdio.h> #include <sys/types.h> #include <sys/stat.h> #include <fcntl.h> #include <errno.h> char* print_errno_msg(int value); int main(void){ struct stat buffer; int status; status =

我编写了这样的示例代码:

#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <errno.h>

char* print_errno_msg(int value);

int main(void){
    struct stat buffer;
    int status;
    status = stat("./main.c", &buffer);
    char *msg = print_errno_msg(errno); /* syntax error : missing ';' before 'type' */

    printf("status = %i; errno = %i; %s\n", status, errno, msg); /* 'msg' : undeclared identifier */
    errno = 0;
    int ch = getchar(); /* syntax error : missing ';' before 'type' */
    return 0;
}

char* print_errno_msg(int value){
    static char *messages[] = {
        "",
        "Operation not permitted",
        "No such file or directory",
        "No such process"
    };
    return messages[value];
}
#包括
#包括
#包括
#包括
#包括
字符*打印错误消息(int值);
内部主(空){
结构统计缓冲区;
智力状态;
status=stat(“./main.c”、&buffer);
char*msg=print_errno_msg(errno);/*语法错误:“type”之前缺少“;”*/
printf(“状态=%i;错误号=%i;%s\n”,状态,错误号,消息);/*“消息”:未声明的标识符*/
errno=0;
int ch=getchar();/*语法错误:“type”之前缺少“;”*/
返回0;
}
字符*打印错误消息(int值){
静态字符*消息[]={
"",
“不允许操作”,
“没有这样的文件或目录”,
“没有这样的程序”
};
返回消息[值];
}
它在Ubuntu12.04中通过gcc进行了良好的编译和执行。我曾尝试通过MS Visual Studio 2012在Windows 8中编译和运行它。我已经创建了空C++项目,并创建了新文件:但我在编译过程中遇到错误(请阅读代码中的注释)

我不理解错误消息。我的语法不对吗?为什么会这样


关于

您正在使用的Unix头文件在Windows上不可用


另一件事是VC++的C编译器只支持C89。这不允许混合声明和代码。所有声明必须位于作用域的开头。

您使用的Unix头文件在Windows上不可用


另一件事是VC++的C编译器只支持C89。这不允许混合声明和代码。所有声明都必须位于作用域的开头。

这在ideone()上编译得很好。当然它不会运行:)“没有这样的文件或目录”我猜你有链接问题。对于MS Visual Studio,某些库可能必须手动设置才能进行编译。看起来VC使用的是严格的C语法。尝试将所有新变量的声明放在main()的顶部附近,可能不允许在函数体中声明变量?如果我是正确的,C89会强制您先声明变量,然后再声明其他变量。众所周知,MSVC会慢慢赶上标准,在本例中是C99。您需要将所有变量声明放在第一条语句之前。这在ideone()上编译得很好。当然它不会运行:)“没有这样的文件或目录”我猜你有链接问题。对于MS Visual Studio,某些库可能必须手动设置才能进行编译。看起来VC使用的是严格的C语法。尝试将所有新变量的声明放在main()的顶部附近,可能不允许在函数体中声明变量?如果我是正确的,C89会强制您先声明变量,然后再声明其他变量。众所周知,MSVC会慢慢赶上标准,在本例中是C99。您需要将所有变量声明放在第一条语句之前。