multiple storage classes: error

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Daniel Schüle

    #1

    multiple storage classes: error

    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


  • Ingo Menger

    #2
    Re: multiple storage classes: error


    Daniel Schüle schrieb:
    [color=blue]
    > Is "static" not allowed in typedef declarations like this or why is the code
    > rejected?[/color]

    Exactly.
    [color=blue]
    > 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?[/color]

    None, since only well formed programs may have semantics.
    [color=blue]
    > I come from C++,[/color]

    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.

    Comment

    Working...