Your code won't even compile.
You can do something like that. Here is one primitive method, pretty much popular is Windows API:
struct VariableSizeStructure {
int someData;
int Array[1]; };
To use this structure, allocate some heap memory more than the size of the structure. For example, if you need
N
elements, allocate the size
sizeof(int) * (N - 1) + sizeof(VariableSizeStructure)
and index
Array
by indices
0
to
N-1
.
[EDIT]
I no way recommend this kind if code design in new development. This technique is good to know just because some APIs use it, but the practice itself is rotten. Don't use it in your own code design!
I really appreciate the valuable comment by Stephan below. Apparently, originally I failed to mention the danger of this approach, not to late to do it now. :-)
—SA