public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
* How to get the Tree ARRAY_TYPE declaration size
@ 2010-03-23  2:23 Massimo Nazaria
  2010-03-23  2:46 ` Ian Lance Taylor
  0 siblings, 1 reply; 3+ messages in thread
From: Massimo Nazaria @ 2010-03-23  2:23 UTC (permalink / raw)
  To: gcc

Hi everyone!

I need to get the array size from a declaration like "int v[100]" (here the size is "100").

For example:
  if (TREE_CODE (TREE_TYPE (var))) == ARRAY_TYPE) {
    int array_size = // ...here I want to get the size
  }

How can I do?

Thank you
Max





^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: How to get the Tree ARRAY_TYPE declaration size
  2010-03-23  2:23 How to get the Tree ARRAY_TYPE declaration size Massimo Nazaria
@ 2010-03-23  2:46 ` Ian Lance Taylor
  2010-03-23 22:30   ` Max N.
  0 siblings, 1 reply; 3+ messages in thread
From: Ian Lance Taylor @ 2010-03-23  2:46 UTC (permalink / raw)
  To: Massimo Nazaria; +Cc: gcc

Massimo Nazaria <max_n@rocketmail.com> writes:

> I need to get the array size from a declaration like "int v[100]" (here the size is "100").
>
> For example:
>   if (TREE_CODE (TREE_TYPE (var))) == ARRAY_TYPE) {
>     int array_size = // ...here I want to get the size
>   }

Quoting gcc/tree.def:

/* Types of arrays.  Special fields:
   TREE_TYPE		  Type of an array element.
   TYPE_DOMAIN		  Type to index by.
			    Its range of values specifies the array length.
 The field TYPE_POINTER_TO (TREE_TYPE (array_type)) is always nonzero
 and holds the type to coerce a value of that array type to in C.
 TYPE_STRING_FLAG indicates a string (in contrast to an array of chars)
 in languages (such as Chill) that make a distinction.  */


In other words, look at TYPE_DOMAIN.  It will often be an INTEGER_TYPE
whose TYPE_MIN_VALUE and TYPE_MAX_VALUE give you the minimum and
maximum valid array indices.

Ian

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: How to get the Tree ARRAY_TYPE declaration size
  2010-03-23  2:46 ` Ian Lance Taylor
@ 2010-03-23 22:30   ` Max N.
  0 siblings, 0 replies; 3+ messages in thread
From: Max N. @ 2010-03-23 22:30 UTC (permalink / raw)
  To: Ian Lance Taylor; +Cc: gcc

Thank you very much! :)



^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2010-03-23 22:01 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-03-23  2:23 How to get the Tree ARRAY_TYPE declaration size Massimo Nazaria
2010-03-23  2:46 ` Ian Lance Taylor
2010-03-23 22:30   ` Max N.

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).