This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: How to get the Tree ARRAY_TYPE declaration size
- From: Ian Lance Taylor <iant at google dot com>
- To: Massimo Nazaria <max_n at rocketmail dot com>
- Cc: gcc at gcc dot gnu dot org
- Date: Mon, 22 Mar 2010 19:23:05 -0700
- Subject: Re: How to get the Tree ARRAY_TYPE declaration size
- References: <973768.19173.qm@web29017.mail.ird.yahoo.com>
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