5 ms·
The two ways (C90 and C99) you can create a variable length item at the end of a structure in C are invalid C++. You can't express them at all. I work around
by dlsspy 14y ago
The two ways (C90 and C99) you can create a variable length item at the end of a structure in C are invalid C++. You can't express them at all.
I work around it by making a one element array and using "sizeof(MyThing) - 1" everywhere when I want to reference the size then use placement new and the ::new operator to do the allocation and initialization of my object.
It works, but it's not very straightforward.
In general, I rather like C++, but it does make a few things harder than C.
- ajross 14y agoYou can't do it for structure fields in C++. The C++ idiom would probably be something like a member function that returned (void*)&this[1].