- To: zahed khurasani <sdzahed@xxxxxxxxx>
- Subject: Re: Global Definition Vs Global Declaration
- From: Ian Lance Taylor <iant@xxxxxxxxxx>
- Date: Thu, 05 Apr 2012 17:12:44 -0700
- Cc: Alexander Monakov <amonakov@xxxxxxxxx>, gcc-help <gcc-help@xxxxxxxxxxx>
- Comment: DKIM? See http://www.dkim.org
- Comment: DomainKeys? See http://antispam.yahoo.com/domainkeys
- In-reply-to: <CAAb5P2tvRB_qh=2L=dVWuGWDgDgR-JmE+_28eF6+0Bozu6gp+Q@mail.gmail.com> (zahed khurasani's message of "Thu, 5 Apr 2012 12:32:06 -0400")
- User-agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux)
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
[Linux C Programming]
[Linux Kernel]
[eCos]
[Fedora Development]
[Fedora Announce]
[Autoconf]
[The DWARVES Debugging Tools]
[Yosemite Campsites]
[Yosemite News]
[Linux GCC]