-1

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()
{

}
4

2 回答 2

2

带有前导双下划线的宏是非法的。您需要更改包含防护。

于 2012-07-04T13:42:42.190 回答
0

你需要;}of之后jumptable_a。并在 的初始化程序中使用逗号而不是分号jumptable_a

大括号使它看起来像某种类似函数,但事实并非如此。

此外,在somefile.hstruct 中被调用table_t,但在somefile.c你正在使用jumptable_t中,我认为这是在这里写帖子时引入的错误。

于 2016-05-25T13:06:12.433 回答