extern variable assignment

Discussion in 'C Programming' started by George2, Feb 12, 2008.

  1. George2

    George2

    Joined:
    Feb 12, 2008
    Messages:
    108
    Hello everyone,


    Statement like this,

    extern int i = 3;

    1. Is it correct?

    2. Is it definition or declaration? Any special function or benefits we could get compared with

    extern int i; or
    int i = 3


    thanks in advance,
    George
    George2, Feb 12, 2008
    #1
    1. Advertising

  2. George2

    vijayan

    Joined:
    Jan 12, 2008
    Messages:
    4
    > extern int i = 3;
    > Is it correct?
    yes.
    > Is it definition or declaration?
    it is both.
    Code:
    extern int i; // declaration
    int i=3 ; // definition
    
    > Any special function or benefits we could get
    not really. by default i would have external linkage; so
    Code:
    extern int i = 3 ;
    and
    Code:
    int i = 3 ; 
    are equivalent.

    Code:
    extern const int c = 3 ;
    here, without the extern, c would have intenal linkage (constant).
    vijayan, Feb 12, 2008
    #2
    1. Advertising

  3. George2

    George2

    Joined:
    Feb 12, 2008
    Messages:
    108
    Thanks vijayan,


    Sorry I do not quite understand your points above. Could you show me the code of external/internal linkage please?

    BTW: I have this confusion is because, for global variables and functions, if we do not add extern, it is by default added, and static (on the other side) is not as default. So I am confused what do you mean if extern is not added, the linkage will changed from external to internal? Internal means static?


    regards,
    George
    George2, Feb 13, 2008
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Thomas Matthews
    Replies:
    5
    Views:
    2,367
    tom_usenet
    Aug 2, 2004
  2. nagy
    Replies:
    36
    Views:
    975
    Terry Reedy
    Jul 20, 2006
  3. Chris
    Replies:
    34
    Views:
    1,477
  4. Derek Basch
    Replies:
    8
    Views:
    127
    Ben Morrow
    Aug 12, 2006
  5. Andre
    Replies:
    5
    Views:
    517
    Keith Thompson
    Jul 17, 2012
Loading...

Share This Page