C/C++

NAVIGATION
CATEGORIES
REFERRENCE
LINKS
  • multiple storage classes: error

    1 answers - 1083 bytes - related search similar search Add To My Delicious Add To My Stumble Upon Add To My Google Mark Add To My Facebook Add To My Digg Add To My Reddit

    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
  • No.1 | | 603 bytes | |


    Daniel S schrieb:

    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.

Re: multiple storage classes: error


max 4000 letters.
Your nickname that display:
In order to stop the spam: 4 + 3 =
QUESTION ON "C/C++"

EMSDN.COM