What does the 'static' in "vector<static FixPt> Data1024;" stand for?

This is a discussion on What does the 'static' in "vector<static FixPt> Data1024;" stand for? within the C++ Programming forums, part of the General Programming Boards category; Hi folks, I am a newcomer to C++ and am reading a example code right now. In this example code, ...

  1. #1
    Registered User
    Join Date
    Sep 2006
    Posts
    10

    What does the 'static' in "vector<static FixPt> Data1024;" stand for?

    Hi folks,

    I am a newcomer to C++ and am reading a example code right now. In this example code, the author used a lot of
    Code:
    vector<static DataType> somename;
    . I know the static vector definition but wonder what's the different between
    Code:
    static vector<int> var1
    and
    Code:
    vector<static int> var2
    ? Can anybody explain this for me? Thanks a lot.


    Cuthbert

  2. #2
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    6,301
    Quote Originally Posted by cuthbert View Post
    Hi folks,

    I am a newcomer to C++ and am reading a example code right now. In this example code, the author used a lot of
    Code:
    vector<static DataType> somename;
    . I know the static vector definition but wonder what's the different between
    Code:
    static vector<int> var1
    and
    Code:
    vector<static int> var2
    ? Can anybody explain this for me? Thanks a lot.
    I'm pretty sure it means nothing in that context. It does compile though.
    Kinda unexpected that the language even allows it.
    My homepage
    Advice: Take only as directed - If symptoms persist, please see your debugger

    Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"

  3. #3
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,662
    It shouldn't compile. Who knows what your compiler may be doing - unless it documents what it does in this case.

    Quote Originally Posted by ISO/IEC 14882:2003(E)
    14.1 - 2
    There is no semantic difference between class and typename in a template-parameter. typename followed by an unqualified-id names a template type parameter. typename followed by a qualified-id denotes the type in a non-type parameter-declaration. A storage class shall not be specified in a template-parameter declaration.
    gg

  4. #4
    Registered User
    Join Date
    Sep 2006
    Posts
    10
    Code:
    vector<static int> var2
    still can be complied by VC2005pro. But, it works just like the code without 'static' identifier.

    Thanks for your answers.

  5. #5
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,636
    Quote Originally Posted by cuthbert
    still can be complied by VC2005pro. But, it works just like the code without 'static' identifier.
    Then it looks like a bug in the compiler. This test program fails to compile with both the MinGW port of g++ 3.4.5 and the Comeau online compiler:
    Code:
    #include <vector>
    
    int main()
    {
        std::vector<static int> somename;
    }
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  6. #6
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,893
    Interesting. I wonder if any of these work under MSVC:
    Code:
    sizeof(static int)
    static_cast<static int>(2.2);
    typeid(static int)
    What they have in common is that they use the "type-id" production. If these work, MSVC misparses this production to allow storage class specifiers.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  7. #7
    Registered User C_ntua's Avatar
    Join Date
    Jun 2008
    Posts
    1,853
    Quote Originally Posted by CornedBee View Post
    Interesting. I wonder if any of these work under MSVC:
    Code:
    sizeof(static int)
    static_cast<static int>(2.2);
    typeid(static int)
    What they have in common is that they use the "type-id" production. If these work, MSVC misparses this production to allow storage class specifiers.
    In VS2008pro the two first don't ('static' keyword not permitted in a cast), the second compiles normally.

  8. #8
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    6,301
    I really should stop assuming that things that work under MSVC are part of the language. I know a great deal of things that it supports that aren't, but the list just keeps on growing...
    My homepage
    Advice: Take only as directed - If symptoms persist, please see your debugger

    Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"

  9. #9
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,545
    Well, writing compilers is not easy. I am guessing it is not on purpose but rather due to the infrastructure of the compiler mostly, that things are allowed that should not be.
    But sometimes VS can be even more flexible then a compiler should be...
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Seg Fault in Compare Function
    By tytelizgal in forum C Programming
    Replies: 1
    Last Post: 10-25-2008, 03:06 PM
  2. seg fault at vectornew
    By tytelizgal in forum C Programming
    Replies: 2
    Last Post: 10-25-2008, 01:22 PM
  3. LNK2001 ERROR!!! need help
    By lifeafterdeath in forum C++ Programming
    Replies: 7
    Last Post: 05-27-2008, 05:05 PM
  4. get keyboard and mouse events
    By ratte in forum Linux Programming
    Replies: 10
    Last Post: 11-17-2007, 04:42 PM
  5. [GLUT] Pointers to class methods
    By cboard_member in forum C++ Programming
    Replies: 13
    Last Post: 02-16-2006, 03:03 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21