Static types

Discussion in 'C++' started by cpp_weenie, Oct 9, 2003.

  1. cpp_weenie

    cpp_weenie Guest

    In the class below, what does the keyword "static" do when applied to the
    struct? It seems it does *not* make any member variables declared to be of
    type "bar" static...

    class foo
    {
    public:
    static struct bar
    {
    int data_1;
    int data_2;
    };

    bar data;
    };
    cpp_weenie, Oct 9, 2003
    #1
    1. Advertising

  2. cpp_weenie

    cpp_weenie Guest

    > In the class below, what does the keyword "static" do when applied to the
    > struct? It seems it does *not* make any member variables declared to be

    of
    > type "bar" static...
    >
    > class foo
    > {
    > public:
    > static struct bar
    > {
    > int data_1;
    > int data_2;
    > };
    >
    > bar data;
    > };


    Let me update my previous post. I think this is a compiler problem (VC++
    6.0) - it should not be let through. It doesn't compile under g++ and I
    can't find any reference to this type of construct in the Standard.

    If it is indeed a compiler problem, sorry to have asked a non-question.
    Hope nobody burned too much time on this one...
    cpp_weenie, Oct 9, 2003
    #2
    1. Advertising

  3. cpp_weenie

    Ron Natalie Guest

    "cpp_weenie" <> wrote in message news:...
    > In the class below, what does the keyword "static" do when applied to the
    > struct? It seems it does *not* make any member variables declared to be of
    > type "bar" static...
    >
    > class foo
    > {
    > public:
    > static struct bar
    > {
    > int data_1;
    > int data_2;
    > };
    >
    > bar data;
    > };
    >

    In this case, absolutey nothing.
    If it said:
    static struct bar {
    int data_1;
    int data_2;
    } data;

    the static applies to data (making it a static member).
    Ron Natalie, Oct 9, 2003
    #3
  4. cpp_weenie wrote in news::

    >> In the class below, what does the keyword "static" do when applied to
    >> the struct? It seems it does *not* make any member variables
    >> declared to be

    > of
    >> type "bar" static...
    >>
    >> class foo
    >> {
    >> public:
    >> static struct bar
    >> {
    >> int data_1;
    >> int data_2;
    >> };
    >>
    >> bar data;
    >> };

    >
    > Let me update my previous post. I think this is a compiler problem
    > (VC++ 6.0) - it should not be let through. It doesn't compile under
    > g++ and I can't find any reference to this type of construct in the
    > Standard.
    >


    I don't know which is right g++ tells you it doesn't make any sense
    and msvc 6.0 just ignores the static. It may well be that this is
    implementation defined behaviour, so both could be conforming.

    > If it is indeed a compiler problem, sorry to have asked a
    > non-question. Hope nobody burned too much time on this one...
    >


    Perhapse this will help it all make sense note the 'variable'
    identifiyer:

    #include <iostream>

    class foo
    {
    public:
    static struct bar
    {
    int data_1;
    int data_2;
    } variable;

    bar data;
    };

    foo::bar foo::variable = { 10, 12 };

    int main()
    {
    std::cerr << foo::variable.data_1 << "\n";
    }

    Rob.
    --
    http://www.victim-prime.dsl.pipex.com/
    Rob Williscroft, Oct 9, 2003
    #4
  5. cpp_weenie

    Ron Natalie Guest

    "Rob Williscroft" <> wrote in message news:Xns940F18AD13763ukcoREMOVEfreenetrtw@195.129.110.130...

    >
    > I don't know which is right g++ tells you it doesn't make any sense
    > and msvc 6.0 just ignores the static. It may well be that this is
    > implementation defined behaviour, so both could be conforming.


    It's not conforming. If you place a storage class specifier (such
    as static), then you have to go ahead and declare a variable.
    Standard section 7.1.1. Says so in the third sentence of that section.
    Ron Natalie, Oct 9, 2003
    #5
  6. cpp_weenie

    cpp_weenie Guest

    > It's not conforming. If you place a storage class specifier (such
    > as static), then you have to go ahead and declare a variable.
    > Standard section 7.1.1. Says so in the third sentence of that section.


    As an additional note, I just tried it under VC++ 7.1 as well. I found that
    it let this non-conforming construct through without so much as a warning!

    Bill did pretty good this time around, but I have found several little
    things like this...
    cpp_weenie, Oct 9, 2003
    #6
  7. "cpp_weenie" <> wrote in message
    news:...
    > > It's not conforming. If you place a storage class specifier (such
    > > as static), then you have to go ahead and declare a variable.
    > > Standard section 7.1.1. Says so in the third sentence of that section.

    >
    > As an additional note, I just tried it under VC++ 7.1 as well. I found that
    > it let this non-conforming construct through without so much as a warning!
    >

    Yep..VC++ 7 doesn't crib even with /Za (disable language extensions).
    Many times compilers differ in their behavior on the same code.
    IMO, one should compile code (standard C++) on atleast two compilers.
    Referring to the standard definitely tells which compiler is correct but may
    times the interpretation is left to the reader.
    In such cases I personally trust Comeau's implementation. Nice to see a compiler
    which can claim to be almost standard compliant.
    ( I read somewhere that Comeau has some problems with Koenig lookup)

    HTH,
    J.Schafer
    Josephine Schafer, Oct 9, 2003
    #7
    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. Sathyaish
    Replies:
    2
    Views:
    582
    Sathyaish
    May 22, 2005
  2. Soren Kuula
    Replies:
    2
    Views:
    543
    Henry S. Thompson
    Dec 1, 2005
  3. Jeremy Cowles

    STD types vs C++ intrinsic types

    Jeremy Cowles, Aug 18, 2003, in forum: C++
    Replies:
    5
    Views:
    1,866
    Bob Jacobs
    Aug 19, 2003
  4. Steve Knight
    Replies:
    2
    Views:
    743
    Steve Knight
    Oct 10, 2003
  5. Manlio Perillo

    missing types in module types?

    Manlio Perillo, May 29, 2004, in forum: Python
    Replies:
    0
    Views:
    341
    Manlio Perillo
    May 29, 2004
Loading...

Share This Page