[英]C code compiles in Windows, gives compilation error on Linux
somefile.h 的內容:
#ifndef __SOMEFILE_H
#define __SOMEFILE_H
#ifdef __cplusplus
extern "C" {
#endif
typedef struct _table_t
{
void (*somefunction1)();
void (*somefunction2)(int a);
void (*somefunction3)(int a, int *b);
}table_t;
void doSomething1();
void doSomething2();
#ifdef __cplusplus
} // error at this line: expected constructor, destructor, or type conversion before '(' token
#endif
#endif
上面顯示的是代碼片段和我在 Linux 上編譯代碼時遇到的錯誤。 相同的代碼在 Windows 上編譯得很好,沒有任何抱怨。
關於源文件:
all.h is a header file which includes:
#include "header1.h"
#include "header2.h"
#include "header3.h"
#include "somefile.h"
這是 somefile.c 的內容
#include "all.h"
#include "header4.h"
jumptable_t jumptable_a =
{
a_function1();
a_function2(int a);
a_function3(int a, int *b);
}
//more code
void function1()
{
a_function1();
}
void function2(int a)
{
a_function2(a);
}
void function3(int a, int *b)
{
a_function3(a, b);
}
void doSomething1()
{
}
void doSomething2()
{
}
帶有前導雙下划線的宏是非法的。 你需要改變你的包含守衛。
你需要一個;
在jumptable_a
的}
之后。 並在jumptable_a
的初始化程序中使用逗號而不是分號。
大括號使它看起來像某種類似於函數的東西,但事實並非如此。
此外,在somefile.h
中,該結構稱為table_t
,但在somefile.c
中,您使用的是jumptable_t
,我認為這是在此處撰寫帖子時引入的錯誤。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.