Thread: Wierd warning?

  1. #1
    Registered User
    Join Date
    Feb 2005
    Posts
    8

    Smile Wierd warning?

    I get a warning when i declare a global integer variable extern?
    Code:
    extern int compflag
    warning: compflag initialized and declared extern
    but when initialize a char variable extern from some old code i found I don't have the same warning. This is causing a problem, I'm just curious as to why an integer does not need the extern while the char does?
    Thanx a bunch for answering a really pointless question!

  2. #2
    Registered User
    Join Date
    Sep 2004
    Location
    California
    Posts
    3,268
    I'm guessing the warning is due to you doing something like:

    Code:
    extern int compflag = 10;
    You should only initialize the variable where it is declared (not declared as extern). For example, what if you had the following in one file:
    Code:
    extern int compflag = 10;
    and in another file you have:
    Code:
    int compflag = 11;
    What does the value of compflag get initialized to?

  3. #3
    Registered User
    Join Date
    Feb 2005
    Posts
    8
    i declare it
    Code:
    extern int compflag =0;
    and there is no other declaration of it elsewhere.

  4. #4
    Registered User
    Join Date
    Feb 2005
    Posts
    8
    I got rid of the initialization since the value that is stored gets changed at the start of each function that need it. It worked to I don't get that warning.
    Thank you for your explaination.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 10
    Last Post: 07-10-2008, 03:45 PM
  2. Screwy Linker Error - VC2005
    By Tonto in forum C++ Programming
    Replies: 5
    Last Post: 06-19-2007, 02:39 PM
  3. <Gulp>
    By kryptkat in forum Windows Programming
    Replies: 7
    Last Post: 01-14-2006, 01:03 PM
  4. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 06:39 AM
  5. Interface Question
    By smog890 in forum C Programming
    Replies: 11
    Last Post: 06-03-2002, 05:06 PM