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


> On Tue, 8 Oct 2002 13:35:41 +0100, Neil Booth <neil@daikokuya.co.uk> wrote:
> 
> > Jason Merrill wrote:-
> >
> >> 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.
> 
> But first isn't a VLA.  To actually use a VLA in a struct would mean an
> example like
> 
>   int foo_length;
>   struct foo
>   {
>     int arr[foo_length];
>   };
> 
>   void f ()
>   {
>     foo_length = 42;
>     {
>       foo bar;
>       bar.arr[12] = 24;
>     }
>   }

Except, of course, that c99 says that only an "ordinary indentifier" may 
be a VLA.  So you can't have a VLA inside a struct and be conforming.

R.


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