variable sized array

Hi all,

just a quick question, in llvm::TargetData,

uint64_t MemberOffsets[1]; // variable sized array!

MemberOffsets has two elements, why it’s variable sized ?

yuanfang

Hi Yuanfang,

just a quick question, in llvm::TargetData,

uint64_t MemberOffsets[1]; // variable sized array!

MemberOffsets has two elements, why it's variable sized ?

when a StructLayout object is allocated (in TargetData::getStructLayout),
extra memory is allocated, more than that given by the size of the type.
The extra memory is interpreted as being part of the MemberOffsets array,
and is used for storing additional member offsets beyond the first one.

This kind of trick generates warnings with gcc-4.5. Maybe it can be done
better. I thought you were supposed to use
   uint64_t MemberOffsets[];
but perhaps I am mistaken.

Ciao,

Duncan.

uint64_t MemberOffsets[];

is a C99 way of doing it (and the only standard way), but it's not a legal C++.

Eugene