shaanxxx said:
> I have following code .
> #include<stdio.h>
> int i;
Tentative definition.
> int i;
Tentative definition.
> int i;
Tentative definition.
Why three?
> It compiles fine .
Yes, - but... why?
> now i modify above code to
>
> #include<stdio.h>
> int i = 0;
Definition and initialisation.
> int i;
Tentative definition.
> int i;
Tentative definition.
But... *why*?
>
> int main()
> {
> printf("%d",i);
> return 0;
> }
>
> again it compiles fine.
>
> now i introduce more change to above code
>
> #include<stdio.h>
> int i = 0;
Definition and initialisation.
> int i = 0;
Definition and initialisation. That's two for-sure definitions with the same
name, which is a for-sure error. And it has to be asked... WHY?
> int i;
Tentative definition.
> int main()
> {
> printf("%d",i);
> return 0;
> }
>
> It gives me redefination Error.
>
> Ok it means that statement 'int i;' is just a declaration. I guess, it
> is not just a declaration since our very first code(code with all 'int
> i;') compiled with no error. There exists atleast one defination of
> 'i'. what should we say to statement 'int i;' ?
"Don't do it" is the obvious answer, surely?
--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at above domain (but drop the www, obviously)