Thread: "extern const int" creates linking errors that "extern int" doesn't

  1. #16
    Registered User
    Join Date
    Jan 2005
    Location
    Estonia
    Posts
    131
    Quote Originally Posted by citizen
    > ok, I don't understand it
    The whole point of the extern keyword is to extend a variable's lifespan beyond file scope. It allows global constants to exist across an entire project.

    Vart's quote from the standard states that constants are linked internally in C++ by default, allowing you to initialize a constant in a header file. In the language's predecessor, C, constants weren't allowed to be initialized in header files, so extern was used. C++ supports the extern keyword because it was inherited from C. If someone can prove that a constant must or shall be linked internally, then I'll gladly shut up.
    Do you know any good links that have examples of what you just said? For me, it's hard to learn without examples and just by someone's theoretical talk.

  2. #17
    Lurking whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    9,612
    > For me, it's hard to learn without examples
    I already gave you an example on the previous page.

    > and just by someone's theoretical talk.
    It's not theory. Vart doesn't think I'm following the ANSI Standard, but he's over-extending the rule he quoted: That is my only problem with what he's saying. I don't really care either way whether you use extern or not, it doesn't matter.
    Last edited by whiteflags; 12-15-2006 at 10:52 AM.

  3. #18
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,788
    Quote Originally Posted by citizen
    Vart doesn't think I'm following the ANSI Standard,
    Never said that... just tried with VC++2005Express and it wasn't working...
    All problems in computer science can be solved by another level of indirection,
    except for the problem of too many layers of indirection.
    – David J. Wheeler

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Polynomials and ADT's
    By Emeighty in forum C++ Programming
    Replies: 20
    Last Post: 08-19-2008, 08:32 AM
  2. Undefined Reference Compiling Error
    By AlakaAlaki in forum C++ Programming
    Replies: 1
    Last Post: 06-27-2008, 11:45 AM
  3. problem with const int inside class (c2258)
    By talz13 in forum C++ Programming
    Replies: 1
    Last Post: 11-23-2003, 07:34 PM
  4. vector<>
    By teval in forum C++ Programming
    Replies: 11
    Last Post: 08-18-2003, 03:27 PM
  5. errors in class(urgent)
    By ayesha in forum C++ Programming
    Replies: 2
    Last Post: 11-10-2001, 06:51 PM