Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Undocumented GCC Extension: VLA in struct

While reading the Clang documentation, I came across the following intriguing tidbit: [1]

clang does not support the gcc extension that allows variable-length arrays in structures. This is for a few reasons: one, it is tricky to implement, two, the extension is completely undocumented, and three, the extension appears to be rarely used. Note that clang does support flexible array members (arrays with a zero or unspecified size at the end of a structure).

How can this extension be used? My understanding is that using alloca within a constructor causes the stack pointer to be restored at the end of the calling function, which in this case would be the constructor -- not at the end of the enclosing struct.

Thanks for the help!

like image 769
void-pointer Avatar asked Aug 21 '12 15:08

void-pointer


1 Answers

See http://gcc.gnu.org/bugzilla/show_bug.cgi?id=37428

and also http://gcc.gnu.org/bugzilla/show_bug.cgi?id=42121

Yes, it's weird.

like image 64
Jonathan Wakely Avatar answered Oct 10 '22 22:10

Jonathan Wakely