multiple storage classes: error

Discussion in 'C Programming' started by Daniel Schüle, Nov 28, 2005.

  1. 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
    Daniel Schüle, Nov 28, 2005
    #1
    1. Advertising

  2. Daniel Schüle

    Ingo Menger Guest

    Daniel Schüle 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.
    Ingo Menger, Nov 28, 2005
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Christoph Schuster

    ASP.NET Error: Not enought storage is available

    Christoph Schuster, Aug 26, 2003, in forum: ASP .Net
    Replies:
    5
    Views:
    10,361
    Christoph Schuster
    Aug 27, 2003
  2. Dave Wright
    Replies:
    3
    Views:
    407
    .NET Follower
    Feb 9, 2004
  3. JHenstay
    Replies:
    3
    Views:
    539
    osmium
    Jan 11, 2004
  4. sarathy
    Replies:
    2
    Views:
    649
    sarathy
    Jul 17, 2006
  5. sumsin
    Replies:
    2
    Views:
    453
    James Kanze
    Jun 7, 2008
Loading...

Share This Page