0

WinFUSE ライブラリを試しているところ、奇妙なコンパイラ エラー メッセージが表示されます。

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

出力は次のとおりです。

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

REFLINE 1 または REFLINE 2のいずれかをコメントすると、コンパイルは正常に機能します。

1:作品

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:作品

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

質問

これはバグですか、それとも間違っていますか? 私はコンパイルしています

Microsoft (R) C/C++ 最適化コンパイラ バージョン 17.00.60315.1 for x86

4

1 に答える 1

2

Microsoft コンパイラは C89 のみをサポートするため、宣言とコードの混在を許可しません (これは C99 で追加されました)。すべての変数宣言は、他の何よりも前に、各ブロックの先頭に配置する必要があります。これも機能します:

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);
}
于 2013-05-27T19:41:14.403 に答える