Thread: usage of extern keyword

  1. #1
    Registered User
    Join Date
    May 2007
    Posts
    5

    Unhappy usage of extern keyword

    can some pro quickly explain what's the use of extern keyword?

    sometimes i see a function declared as:
    extern int myFunc();

    what does the extern do there?

  2. #2
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,005
    7. It is easier to write an incorrect program than understand a correct one.
    40. There are two ways to write error-free programs; only the third one works.*

  3. #3
    Officially An Architect brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,396
    Quote Originally Posted by ilikepure View Post
    can some pro quickly explain what's the use of extern keyword?

    sometimes i see a function declared as:
    extern int myFunc();

    what does the extern do there?
    It is redundant and not necessary (for function prototypes, as in your case).

    The only reason you would be using extern is if you were using global variables across modules. And global variables, as most people agree, are a bad thing, so if you see the word "extern" you should probably be thinking "bad code," or at least code that could be improved.

    EDIT: Of course, there is the extern "C" thing, but that's just the extern keyword hacked into a new role. If you aren't calling C code from C++ code, there is no need for it.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. extern classes
    By Swordsman in forum C++ Programming
    Replies: 1
    Last Post: 05-07-2008, 02:07 AM
  2. Replies: 16
    Last Post: 10-29-2006, 05:04 AM
  3. extern keyword
    By trekker in forum C Programming
    Replies: 7
    Last Post: 06-01-2005, 01:31 PM
  4. extern keyword
    By Shadow12345 in forum C++ Programming
    Replies: 1
    Last Post: 05-26-2002, 12:33 PM
  5. extern keyword and structures
    By GuitGentlyWeeps in forum C Programming
    Replies: 2
    Last Post: 01-30-2002, 07:02 AM