Massimo Nazaria <ma...@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

Reply via email to