Declaring struct as static is causing problem.

Discussion in 'C++' started by param, Jan 13, 2006.

  1. param

    param Guest

    Declaring struct as static is creating problem with newer version of CC
    compiler 5.7 in solaris.

    e.g.

    static struct new_str {
    int a;
    int b;
    };

    It shows the Error : "static" is not allowed here.

    Pls help me out of this problem. Also what is the significance of
    declaring type as static ....as is shown above for new type new_str.

    Regards
    Parminder
     
    param, Jan 13, 2006
    #1
    1. Advertising

  2. param

    Daevaorn Guest

    struct new_str { //type cannot be static!
    int a;
    int b;
    };

    static new_str a; //declare a static variable
     
    Daevaorn, Jan 13, 2006
    #2
    1. Advertising

  3. param

    param Guest

    hi Daevaorn ,

    That's true that type cannot be static. But this code was working fine
    with earlier compiler
    i.e. CC 4.2. I want to know what was the benefit of declaring "static
    struct" at that time.

    May be it was that :
    1.) static was used so that it has global visiblity only in the
    declaration file.
    2.) or was it declared with the notion that declaring static struct
    will force all the variables of this type to be initialized with
    defailt values.

    I don't know i am confused. what was the significance of declaring it
    that way.

    Regards
    Parminder
     
    param, Jan 13, 2006
    #3
  4. param

    Daevaorn Guest

    hmm...
    May be this is the solve:

    struct new_str {
    int a;
    int b;
    } var; // that code works fine
     
    Daevaorn, Jan 13, 2006
    #4
  5. param

    Daevaorn Guest

    hmm...
    May be this can solve problem:

    struct new_str {
    int a;
    int b;
    } var; // that code works fine
     
    Daevaorn, Jan 13, 2006
    #5
  6. param

    Jack Klein Guest

    On 13 Jan 2006 01:07:26 -0800, "param" <> wrote in
    comp.lang.c++:

    > hi Daevaorn ,
    >
    > That's true that type cannot be static. But this code was working fine
    > with earlier compiler
    > i.e. CC 4.2. I want to know what was the benefit of declaring "static
    > struct" at that time.


    There was no benefit, it's just that the compiler had a defect, so
    someone wrote sloppy code that did not generate a diagnostic.

    --
    Jack Klein
    Home: http://JK-Technology.Com
    FAQs for
    comp.lang.c http://c-faq.com/
    comp.lang.c++ http://www.parashift.com/c -faq-lite/
    alt.comp.lang.learn.c-c++
    http://www.contrib.andrew.cmu.edu/~ajo/docs/FAQ-acllc.html
     
    Jack Klein, Jan 15, 2006
    #6
    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. Chris Fogelklou
    Replies:
    36
    Views:
    1,422
    Chris Fogelklou
    Apr 20, 2004
  2. Chris Barts
    Replies:
    8
    Views:
    400
    Flash Gordon
    Jan 17, 2005
  3. Replies:
    2
    Views:
    757
    David Harmon
    Sep 20, 2006
  4. Mark Hobley

    Declaring an external variable as a struct

    Mark Hobley, Mar 25, 2010, in forum: C Programming
    Replies:
    19
    Views:
    1,583
    Keith Thompson
    Mar 31, 2010
  5. Richard Mathis

    Issues with declaring struct arrays inside of a struct

    Richard Mathis, Oct 10, 2003, in forum: ASP .Net Building Controls
    Replies:
    0
    Views:
    252
    Richard Mathis
    Oct 10, 2003
Loading...

Share This Page