This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Variable-sized types vs. templates


Jason Merrill wrote:-

> The restrictions on use of VLAs in C99 seem appropriate here: a pointer to
> VLA (and more complex versions of same) is called a variably modified (VM)
> type.  Only a parameter or local variable can have VM type.  A VLA cannot
> have static storage duration.
> 
> Similarly, I think it's appropriate to say that neither VLA nor VM types
> are valid template type arguments.  I'd also say that a VLA is not a valid
> type for a struct member; I don't understand why C99 seems to allow that.
> Perhaps it wants to allow it so that uses in different functions can have
> different sizes, but that seems incompatible with the stronger C++ model of
> struct types.

I think they wanted to formalize hacks like:

/* Chained list of answers to an assertion.  */
struct answer
{
  struct answer *next;
  unsigned int count;
  cpp_token first[1];
};

Where first is an array of size determined at run time.

Neil.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]