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

This is a discussion on "extern const int" creates linking errors that "extern int" doesn't within the C++ Programming forums, part of the General Programming Boards category; Originally Posted by citizen > ok, I don't understand it The whole point of the extern keyword is to extend ...

  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
    Registered User whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    7,740
    > 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 09:52 AM.

  3. #18
    CSharpener vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,484
    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...
    The first 90% of a project takes 90% of the time,
    the last 10% takes the other 90% of the time.

Page 2 of 2 FirstFirst 12
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, 06: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, 05:51 PM

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