extern variable assignment

Joined
Feb 12, 2008
Messages
108
Reaction score
0
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
 
Joined
Jan 12, 2008
Messages
4
Reaction score
0
> 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).
 
Joined
Feb 12, 2008
Messages
108
Reaction score
0
Thanks vijayan,


vijayan said:
c would have intenal linkage (constant).

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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,042
Latest member
icassiem

Latest Threads

Top