This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: Variable-sized types vs. templates
- From: Jim Wilson <wilson at redhat dot com>
- To: Mark Mitchell <mark at codesourcery dot com>
- Cc: gcc at gcc dot gnu dot org, nathan at codesourcery dot com, jason at redhat dot com, gdr at codesourcery dot com
- Date: 08 Oct 2002 12:12:45 -0400
- Subject: Re: Variable-sized types vs. templates
- References: <1300000.1033752147@localhost><xwubs6553mo.fsf@tonopah.toronto.redhat.com>
>A key difference between the two is that GNU C dynamic arrays can exist inside
>a structure, and VLAs can not. This means GNU C has variable sized types,
>but ISO C99 does not. Variable sized types complicates things like argument
>passing, so it is understandable that ISO C99 left this out. I can also see
>that it complicates stuff like template instantiation, so it would make sense
>to leave this out of the C++ language also.
I was a little too hasty here. ISO C99 has VLAs, and VLAs are obviously
variable sized types. What I meant to say was that ISO C99 can never have
an argument with a variable sized type. Arrays decay to pointers when used
as arguments, and VLAs aren't allowed inside structures, so there is no way
to get a variable sized argument in ISO C99. There isn't any other place in C
where variable sized types are a problem. There are other places in C++, but
the VLA rules may be enough to avoid all problems.
GNU C dynamic arrays can be used to create variable sized arguments. The
Ada language can also have variable sized arguments, and the GNU C dynamic
arrays feature can be useful for testing support needed for Ada.
Jim