[LLVMdev] variable sized array

Duncan Sands baldrick at free.fr
Fri Apr 23 02:31:48 PDT 2010

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.



More information about the llvm-dev mailing list