Global Definition Vs Global Declaration
zahed khurasani
sdzahed@gmail.com
Thu Apr 5 16:33:00 GMT 2012
> 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.
Zahed
More information about the Gcc-help
mailing list