This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: Variable-sized types vs. templates
- From: Richard Earnshaw <rearnsha at arm dot com>
- To: Jason Merrill <jason at redhat dot com>
- Cc: Neil Booth <neil at daikokuya dot co dot uk>, nathan at cs dot bris dot ac dot uk, Mark Mitchell <mark at codesourcery dot com>, gcc at gcc dot gnu dot org, nathan at codesourcery dot com, gdr at codesourcery dot com, Richard dot Earnshaw at arm dot com
- Date: Tue, 08 Oct 2002 14:03:36 +0100
- Subject: Re: Variable-sized types vs. templates
- Organization: ARM Ltd.
- Reply-to: Richard dot Earnshaw at arm dot com
> 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.