[cfe-dev] Adding getTypeSizeInBytes to ASTContext

Douglas Gregor dgregor at apple.com
Mon Nov 23 13:59:42 PST 2009


On Nov 23, 2009, at 11:12 AM, Ken Dyck wrote:

> Sprinkled throughout clang are expressions of the form:
>
> size = Context.getTypeSize(SomeType) / 8;
>
> These expressions quite obviously assume that the width of a byte is 8
> bits.
>
> As a first step in eliminating this assumption and someday supporting
> targets with byte widths other than 8 bits, the attached patch
> introduces two new methods to ASTContext.
>
>  1. getByteSize(): returns the width of the target's character type  
> (on
> all existing targets it returns 8).
>
>  2: getTypeSizeInBytes(T): returns getTypeSize(T) / getByteSize(T),
> i.e. the size of a given type in bytes.
>
> With this patch applied, the above snippet could be replaced with:
>
>  size = Context.getTypeSizeInBytes(SomeType);
>
> The getByteSize() method is intended for use by a follow-on patch that
> will introduce getTypeAlignInBytes() and to replace literal 8s in  
> other
> parts of the code.
>
> Any objections? Comments?

Looks fine to me.

	- Doug



More information about the cfe-dev mailing list