multiple storage classes: error

D

Daniel Schüle

Hello all,

I get the error when I try to compile this code

// .h file

typedef static int (*get)(void); // (*)
typedef static void (*set)(int); //

// .c file

// forward methods
static int getAMethod(void);
static void setAMethod(int);

static struct foo {
get getA;
set setA;
// and so on
}bar = {
.getA = getAMethod,
.setA = setAMethod,
};

// implement methods
static int getAMethod(void) { // do something with bar }
static void setAMethod(int value) { // the same }

-----------------------------
when I remove "static" in (*) then compiler (gcc3.3.5) accepts it
Is "static" not allowed in typedef declarations like this or why is the code
rejected?

And one more question ... suppose I would have

struct foo {
static get getA;
static set setA;
} bar;

what would be the semantic of the "static" in this context?
I come from C++, I dont know is this construct is allowed.
I only know for sure "const" would be ok there.

Thx for your answers
Regards, Daniel
 
I

Ingo Menger

Daniel said:
Is "static" not allowed in typedef declarations like this or why is the code
rejected?
Exactly.

And one more question ... suppose I would have

struct foo {
static get getA;
static set setA;
} bar;

what would be the semantic of the "static" in this context?

None, since only well formed programs may have semantics.
I come from C++,

I see. In C, write the static members outside the struct to get nearly
the same effect. All code referencing the static members must be in the
same source file.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,901
Latest member
Noble71S45

Latest Threads

Top