Contents of 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
Shown above is the code snippet and the error I get when I compile my code on Linux. The same code compiles fine on Windows with no complaints.
About the source file:
all.h is a header file which includes:
#include "header1.h"
#include "header2.h"
#include "header3.h"
#include "somefile.h"
Here is the content of 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()
{
}
Macro with leading double underscores is illegal. You need to change your include guard.
You need a ;
after the }
of jumptable_a
. And use commas instead of semicolons in the initializer of jumptable_a
.
The braces make it look like a somethink function-like, but it's not.
Also, in somefile.h
the struct is called table_t
, but in somefile.c
you are using jumptable_t
, which I assume is an error introduced when writing the post here.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.