This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: Global Definition Vs Global Declaration
zahed khurasani <sdzahed@gmail.com> writes:
>> Unless my knowledge of C is wrong here, both 'int i' and 'extern int i' are
>> indistinguishable declarations (not definitions). ÂAn explicit initialization
>> would be needed to make the second a definition: int i = 0. ÂIsn't this the
>> case here?
>
> Explicitly initializing the variable only has effect on where the
> variable is allocated space. In this case, explicit initialization
> moves the variable out of the common area into the data segment.
> Hence, DECL_COMMON returns 0 when we do this. The point being, both
> are definitions. Where as an extern declaration is an explicit
> reference to an externally defined variable (which can be outside the
> current translation unit). Please correct me if I am wrong on this.
> Appreciate your help.
OK, I actually tried it. When I try this with current mainline, I see
that DECL_EXTERNAL is set for "extern int j;" and is not set for "int
i;". Also TREE_STATIC is set for "int i;" but not for "extern int j;".
Ian