[cfe-dev] Total size of array type

Eli Friedman eli.friedman at gmail.com
Fri Feb 10 13:17:49 PST 2012


On Fri, Feb 10, 2012 at 1:03 PM, Trevor Harmon <trevor at vocaro.com> wrote:
> Hi,
>
> Given a QualType (or Type) handle to an array declaration, I need to
> get the total size in bytes. For example:
>
> int foo[2]    // 8 bytes
> char foo[2]   // 2 bytes
>
> I can get the number of elements using ConstantArray::getSize (which
> returns 2 in the above cases), but I need the size of the element type
> as well, in order to compute the total bytes. However, there's no
> getSize or equivalent for QualType or Type. What am I missing? Thanks,

Try ASTContext::getTypeSizeInChars().

-Eli




More information about the cfe-dev mailing list