This is the mail archive of the 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

You are confusing ISO C99 variable length arrays (VLA) with GNU C dynamic
arrays.  These are related but distincly different features.  GNU C dynamic
arrays predate ISO C99 VLAs by almost 10 years, and it is the dynamic array
support in the C++ front end that is causing problems.

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.

Since dynamic arrays have been around for so long, and are used in so many
programs, the C front end needs to continue supporting dynamic arrays in
addition to VLAs.  There seems to be some confusion here though.  I just
tried writing a simple testcase using a dynamic array that wasn't a valid VLA
and gcc accepted it with -std=c99 -pedantic.  I'm sure this will eventually
be sorted out.

Meanwhile, there probably isn't a lot of need to have dynamic array support
in the C++ front end.  You should support VLAs if at all possible, but you
don't really need dynamic arrays support.  There may be old programs that rely
on dynamic arrays, so you probably should phase this stuff out slowly.  If
a dynamic array is used in a context where it can't possibly work, then give
an error.  if a dynamic array is used in a context where it can work, then
you should continue to support it, but it would be OK to give an "obsolete
feature" warning, and then delete the feature in a future release.

Actually, I just noticed that someone changed the documentation in the
extend.texi file to use the term VLA instead of dynamic array.  I think that
was a mistake, since VLA and dynamic array are not the same thing.

Also, note that Ada has variable sized types, so the GNU C dynamic array
feature has some use for testing features needed for Ada language support.


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