- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
Best regards,
Georg Zitzlsberger
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
unfortunately yes.
You can use pointers & manual (stack) allocation as a workaround, for example:
[bash]#include
Also using macros can surely make the workaround better readable and less error prone.
Best regards,
Georg Zitzlsberger
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I wonder if it will work:
...
#define X 0
#define Y 1
...
...
'p' is for point
Best regards,
Sergey
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
http://www.informit.com/guides/content.aspx?g=cplusplus&seqNum=325
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Just checked withg++ and it successfullycompiles that code:
...
int iSize;
struct VLA
{
void DoProcessing( void )
{
int x[iSize];
int y[iSize];
...
};
};
...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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!
Best regards,
Georg Zitzlsberger
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
Best regards,
Sergey
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
{
public:
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 )
return;
//...
// Some functionality
//...
};
T *m_ptData;
int m_iSize;
};
...
...
void SomeFunction( void )
{
TStackArray< int > iSA( 131072 ); // A 128K array of integers will be allocated on the Stack
iSA.Process();
}
...
Also, if several arrays are needed a main memory block allocated by 'alloca' could be easilyPartitioned.
Best regards,
Sergey
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
Best regards,
Georg Zitzlsberger
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi Georg,
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.
Best regards,
Sergey

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page