Whenever initialisation is attempted, the statement becomes a definition no matter that extern is used. The extern keyword is redundant in such a case because, by default, symbols not marked static already have external linkage.
Up vote 2 down vote favorite share g+ share fb share tw.
While I was reading the answers of Use of 'extern' keyword while defining the variable One of the user answered these way extern int a; // not a definition extern int a = 42; // definition I was expecting both are not definitions but declarations. I was thinking Both statements says that the variable is defined outside the function and we have to use extern keyword to use it. Is this a mistake by him or is it really a definition?
I know that extern int a; // variable is already defined but its outside the function extern int a=42 ; //I guess a variable is assigned a value but not a definition but these statement extern int a = 42; // user said its a definition and now I got confused Please clear me with these. C link|improve this question edited Sep 30 '11 at 12:31NullUserException?29.7k53984 asked Sep 30 '11 at 12:25niko1,684114 100% accept rate.
The declarations being discussed in the linked questions are all assumed to be file scoped declarations, not function scoped. – Charles Bailey Sep 30 '11 at 12:30.
Whenever initialisation is attempted, the statement becomes a definition, no matter that extern is used. The extern keyword is redundant in such a case because, by default, symbols not marked static already have external linkage. It doesn't make sense to declare an external variable and set its initial value in the current compilation unit, that's a contradiction.
Wow! I did not know that c is really a language with a miracles binded in it – niko Sep 30 '11 at 12:30 so You mean extern int a = 42 ; is nothing but int a = 42? Right – niko Sep 30 '11 at 12:31 okay I have got some thoughts on my mind after seeing you answer let me try it on my compiler and update my question if I have any issues with that.
But thanks! – niko Sep 30 '11 at 12:31.
Extern int a; is a declaration. It does not allocate space for storing a. Extern int a = 42; is a definition.
It allocates space to store the int value a and assigns it the value 42.
Here the variables are decleared in side the main() funtion where its definition was defined outside in the global declearation section extreme int a; //is declearation extreme int a=42; // is definition.
Please read the question carefully again! – niko Sep 30 '11 at 12:33.
I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.