Re: Global Definition Vs Global Declaration

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


zahed khurasani <sdzahed@xxxxxxxxx> writes:

>> 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;".
>
> Hmm strange. I am not sure if I am doing this wrong. Here's the sample
> code that I am running this on:
>
> // Global decls
> static int staticint;
> extern int extint;
> int globalint;
>
> int main(void)
> {
>     int a[10],i, *p;
>     globalint=0;
>     return 1;
> }
>
> And here is the output from the plugin code:
>
> Glob var: staticint   decl_external:0 tree_static:1 complete:1 common: 0
> Glob var: extint      decl_external:1 tree_static:0 complete:1 common: 1
> Glob var: globalint decl_external:1 tree_static:0 complete:1 common: 1
>
> decl_external is set for both globalint and extint. I am trying this
> with 4.6.2 source.

I was checking the fields by running cc1 in the debugger.  I was looking
at the point where decls are passed to wrapup_global_declaration_2.

I tried 4.6, and the situation there seems more complicated for some
reason.  Both "extern int j;" and "int i;" have two decls.  Both decls
for j, and one of the ones for i, are DECL_EXTERN and DECL_COMMON.  The
other decl for i is TREE_STATIC and DECL_COMMON but not DECL_EXTERN.
I'm not sure why this is.

Ian



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

Add to Google