Re: Global Definition Vs Global Declaration

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



zahed khurasani <sdzahed@xxxxxxxxx> 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



[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux