在MSVC奇怪的编译器错误 [英] Weird compiler error in MSVC

查看:152
本文介绍了在MSVC奇怪的编译器错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想出来的WinFUSE库,并得到一个奇怪的编译器错误消息。

 的#include<&WINDOWS.H GT;
#包括LT&;&fuse.h GT;无效* fuse_init(结构fuse_conn_info * conn)的{
    的printf(%S(%P)\\ n,__FUNCTION__,康涅狄格州);
    如果返回NULL(康恩!);
    conn-> async_read = TRUE;
    conn-> max_write = 128;
    conn-> max_readahead = 128;
    康涅狄格州返回;
}INT主(INT ARGC,字符** argv的){
    结构fuse_operations OPS = {0};    //填充的操作结构。
    ops.init = fuse_init; //参考线1    无效* USER_DATA = NULL; //参考线2(第26行,错误行)
    返回fuse_main(ARGC,ARGV,&安培; OPS,NULL);
}

输出是:

  C:\\用户\\尼克拉斯\\桌面\\试验> CL main.c中fuse.c / I。 / NOLOGO /链接dokan.lib
main.c中
main.c中(26):错误C2143:语法错误:缺少;前型
fuse.c
生成code ...

在我的评论不是的参考线1 参考线2 的,汇编工作正常。

1:作品

  INT主(INT ARGC,字符** argv的){
    结构fuse_operations OPS = {0};    //填充的操作结构。
    // ops.init = fuse_init; //参考线1    无效* USER_DATA = NULL; //参考线2
    返回fuse_main(ARGC,ARGV,&安培; OPS,NULL);
}

2:作品

  INT主(INT ARGC,字符** argv的){
    结构fuse_operations OPS = {0};    //填充的操作结构。
    ops.init = fuse_init; //参考线1    //无效* USER_DATA = NULL; //参考线2
    返回fuse_main(ARGC,ARGV,&安培; OPS,NULL);
}

问题

这是一个错误还是我做错了?我与编译


  

微软(R)C / C ++优化编译器版本17.00.60315.1用于x86



解决方案

微软编译器支持C89只,因此不允许声明和code(这是在C99加入)的交织。所有的变量声明必须放置在每个块的开始,先天下之忧。这也将工作:

  INT主(INT ARGC,字符** argv的){
    结构fuse_operations OPS = {0};    / *填充的操作结构。 * /
    ops.init = fuse_init;    {
        无效* USER_DATA = NULL;
    }    返回fuse_main(ARGC,ARGV,&安培; OPS,NULL);
}

I'm trying out the WinFUSE library and get a weird compiler error message.

#include <windows.h>
#include <fuse.h>

void* fuse_init(struct fuse_conn_info* conn) {
    printf("%s(%p)\n", __FUNCTION__, conn);
    if (!conn) return NULL;
    conn->async_read = TRUE;
    conn->max_write = 128;
    conn->max_readahead = 128;
    return conn;
}

int main(int argc, char** argv) {
    struct fuse_operations ops = {0};

    // Fill the operations structure.
    ops.init = fuse_init;         // REFLINE 1

    void* user_data = NULL;       // REFLINE 2  (line 26, error line)
    return fuse_main(argc, argv, &ops, NULL);
}

The output is:

C:\Users\niklas\Desktop\test>cl main.c fuse.c /I. /nologo /link dokan.lib
main.c
main.c(26) : error C2143: syntax error : missing ';' before 'type'
fuse.c
Generating Code...

When I comment either REFLINE 1 or REFLINE 2, compilation works fine.

1: Works

int main(int argc, char** argv) {
    struct fuse_operations ops = {0};

    // Fill the operations structure.
    // ops.init = fuse_init;         // REFLINE 1

    void* user_data = NULL;       // REFLINE 2
    return fuse_main(argc, argv, &ops, NULL);
}

2: Works

int main(int argc, char** argv) {
    struct fuse_operations ops = {0};

    // Fill the operations structure.
    ops.init = fuse_init;         // REFLINE 1

    // void* user_data = NULL;       // REFLINE 2
    return fuse_main(argc, argv, &ops, NULL);
}

Question

Is this a bug or am I doing it wrong? I'm compiling with

Microsoft (R) C/C++ Optimizing Compiler Version 17.00.60315.1 for x86

解决方案

The Microsoft compilers support C89 only, and therefore do not permit the intermingling of declarations and code (this was added in C99). All variable declarations must be placed at the beginning of each block, before anything else. This would also work:

int main(int argc, char** argv) {
    struct fuse_operations ops = {0};

    /* Fill the operations structure. */
    ops.init = fuse_init;

    {
        void* user_data = NULL;
    }

    return fuse_main(argc, argv, &ops, NULL);
}

这篇关于在MSVC奇怪的编译器错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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