- To: Swati <swatirathi@xxxxxxxxxxxxxx>
- Subject: Re: How to access initialized values of global variables
- From: Ian Lance Taylor <iant@xxxxxxxxxx>
- Date: Wed, 09 May 2012 11:20:11 -0700
- Cc: gcc-help@xxxxxxxxxxx
- Comment: DKIM? See http://www.dkim.org
- Comment: DomainKeys? See http://antispam.yahoo.com/domainkeys
- In-reply-to: <4FAA84C2.7020902@cse.iitb.ac.in> (Swati's message of "Wed, 09 May 2012 20:22:50 +0530")
- User-agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux)
Swati <swatirathi@xxxxxxxxxxxxxx> writes:
> I am trying to fetch the initialized values of global variables.
> For eg : int i = 10;
>
> I am able to extract the value using DECL_INITIAL.
> But when I have a case like below,
>
> struct node
> {
> int x;
> int y;
> };
>
> struct node n1=
> {
> 99,
> 88,
> };
>
> I get value as {.x=99, .y=88}
>
> How should I iterate to fetch 99 and 88 individually?
> In a way I want to access individual variables initialized values.
> Can someone tell me the way to do it.
I assume you are talking about a GCC plugin here.
The DECL_INITIAL should be a CONSTRUCTOR. CONSTRUCTOR_NELTS is the
number of elements and CONSTRUCTOR_ELTS is the elements themselves. You
can iterate over them using FOR_EACH_CONSTRUCTOR_ELT, which will give
you the index and value for each entry in the constructor. The index
will be a FIELD_DECL.
Ian
[Linux C Programming]
[Linux Kernel]
[eCos]
[Fedora Development]
[Fedora Announce]
[Autoconf]
[The DWARVES Debugging Tools]
[Yosemite Campsites]
[Yosemite News]
[Linux GCC]