[Top][All Lists]

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

Re: [Tinycc-devel] Buiding binutils 2.17 (needs dynamic arrays).

From: Antti-Juhani Kaijanaho
Subject: Re: [Tinycc-devel] Buiding binutils 2.17 (needs dynamic arrays).
Date: Wed, 3 Oct 2007 08:07:21 +0300
User-agent: Mutt/1.5.16 (2007-06-11)

On Tue, Oct 02, 2007 at 12:19:18PM -0500, Rob Landley wrote:
> Any opinions on how to tackle this one?

No.  But I'll summarise (NOT quote) the C99 rules, in case it's helpful.
Feel free to ask questions :)

The C99 term is "variable length array" (VLA).

int a[*] (the asterisk is literal) is allowed in parameter declarations
in function prototypes but not in function definitions.  The array is a
VLA and its length is unknown.

The expression inside [ ] in a variable (or typedef) declaration needs
not be a constant expression.  If it is not constant, then the array is
a VLA.   If the VLA declaration defines a function parameter in a prototype,
the effect is the same as if the expression had been replaced by

When testing array types for compatibility, array sizes are compared
only if both are present and constant.

If a typedef includes VLA types (for example, typedef int foo[n], where
n is not a constant), then the non-constant size expressions are
evaluated when the typedef declaration is encountered during execution.
Thus the size of a VLA typedef is fixed while the typedef name is in
scope.  The standard gives an example in 6.7.7:8:

  EXAMPLE 5 If a typedef name denotes a variable length array type, the
  length of the array is fixed at the time the typedef name is defined,
  not each time it is used:

               void copyt(int n)
                      typedef int B[n]; // B is n ints, n evaluated now
                      n += 1; 
                      B a;              // a is n ints, n without += 1
                      int b[n];         // a and b are different sizes
                      for (int i = 1; i < n; i++)
                              a[i-1] = b[i];

A VLA cannot be initialized explicitly.

When a local VLA variable is declared, the non-constant size expressions
are evaluated at that time.

VLAs are not allowed as struct and union members.

Only local variables may be VLA variables.

It is not allowed to jump over a VLA declaration by goto, switch or
setjmp-longjmp.  The compiler must diagnose violations of this by goto
and switch.

Size expressions of VLA parameters are evaluated when the function is

The size of a VLA variable does not change during the variable's

Antti-Juhani Kaijanaho, Jyväskylä, Finland

reply via email to

[Prev in Thread] Current Thread [Next in Thread]