according to the C99 standard VLAs are not allowed to be members of structs & unions.
On the other hand I can confirm that GCC supports your example. We only seem to allow a struct with just one VLA - removing member "int y" works.
For better GCC compatibility I'll file a ticket (edit: DPD200228467) and let you know when implemented.
For the time being, the only workaround is to avoid VLAs as struct/union members like that.
You can use pointers & manual (stack) allocation as a workaround, for example:
Also using macros can surely make the workaround better readable and less error prone.
adding this feature for the current version (Intel Composer XE 2011 and all its update versions) cannot be done. However, the next major product version will contain support for this kind of VLAs.
Thank you for bringing this up!
I understood that VLAs aredependant on 'alloca' CRT function. I've done some investigationfor 'alloca' CRT function
and it doesn't allow to create two arrays in the same scope of some function. A workaround could be used instead by Partitioning of allocated memory.
Why should somebody wait for a builtin support of VLAs in some C/C++ compiler? There are some
limitations with VLAs at the moment and they won't go away easily. Isn't that better to use some kind of workaround?
Here is an example of portable C++ template class that could be used instead:
template< class T > struct TStackArray
TStackArray( int iSize )
m_ptData = NULL;
m_iSize = iSize;
virtual inline void Process( void )
m_ptData = ( T * )alloca( sizeof( T ) * m_iSize );
if( m_ptData == NULL )
// Some functionality
void SomeFunction( void )
TStackArray< int > iSA( 131072 ); // A 128K array of integers will be allocated on the Stack
Also, if several arrays are needed a main memory block allocated by 'alloca' could be easilyPartitioned.
what makes you think there's such a limitation for alloca? To my knowledge you can use it as many times as you want (even per scope) unless you exceed stack limits, of course.
Thank you for the note and brining my attention again.
The situation is very interesting because'alloca' didn't work as expected with Visual Studio 2005 without SP1 and
I couldn'tallocate two memory blocks with 'alloca' in a function or in some scope.
Aboutone weekago I've installed SP1 for Visual Studio 2005 and then 3 days agoyou've posted a message.
So, I've just completed re-testing and, to my surprize, 'alloca' succesfully allocated two memory blocks in my test cases.
I'm really glad that aproblem with 'alloca'was resolved.
Theidea to do Partitioning came to my mind aftera set ofunsuccessful attempts to allocate several memory blocks
with 'alloca' in the same scope.