Thread: why extern getting error

  1. #1
    Registered User
    Join Date
    Dec 2009
    Posts
    16

    why extern getting error

    Code:
    extern int i=30;
    int main()
    {
    printf("%d \n",i);
    return 0;
    }
    output : warning: ‘i’ initialized and declared ‘extern’

    Code:
    int main()
    {
    extern int i=30;
    printf("%d \n",i);
    return 0;
    }
    out put : error: ‘i’ has both ‘extern’ and initializer

    any one can suggest me why in one program getting erro and why in another program getting warining?

  2. #2
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300
    The error and the warning both say the same thing:

    ‘i’ initialized and declared ‘extern’
    ‘i’ has both ‘extern’ and initializer

    What do you think that means?
    C programming resources:
    GNU C Function and Macro Index -- glibc reference manual
    The C Book -- nice online learner guide
    Current ISO draft standard
    CCAN -- new CPAN like open source library repository
    3 (different) GNU debugger tutorials: #1 -- #2 -- #3
    cpwiki -- our wiki on sourceforge

  3. #3
    DESTINY BEN10's Avatar
    Join Date
    Jul 2008
    Location
    in front of my computer
    Posts
    804
    I'm not getting any error or warning with the first code.
    HOPE YOU UNDERSTAND.......

    By associating with wise people you will become wise yourself
    It's fine to celebrate success but it is more important to heed the lessons of failure
    We've got to put a lot of money into changing behavior


    PC specifications- 512MB RAM, Windows XP sp3, 2.79 GHz pentium D.
    IDE- Microsoft Visual Studio 2008 Express Edition

  4. #4
    Registered User
    Join Date
    Oct 2008
    Location
    TX
    Posts
    2,059
    Quote Originally Posted by BEN10 View Post
    I'm not getting any error or warning with the first code.
    Depends on whether you're using a C or C++ compiler.

  5. #5
    C/Linux Programmer
    Join Date
    Dec 2009
    Posts
    17
    Why do you need extern here, first of all?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. LDAP Query
    By Travoiz in forum C++ Programming
    Replies: 0
    Last Post: 08-13-2009, 02:58 PM
  2. Testing some code, lots of errors...
    By Sparrowhawk in forum C Programming
    Replies: 48
    Last Post: 12-15-2008, 04:09 AM
  3. Another syntax error
    By caldeira in forum C Programming
    Replies: 31
    Last Post: 09-05-2008, 01:01 AM
  4. Replies: 16
    Last Post: 10-29-2006, 05:04 AM
  5. Post...
    By maxorator in forum C++ Programming
    Replies: 12
    Last Post: 10-11-2005, 08:39 AM