[cfe-dev] Helpers to compute sizeof/alignof/offsetof?
Ted Kremenek
kremenek at apple.com
Thu Jan 17 21:02:39 PST 2008
On Jan 17, 2008, at 7:35 PM, Chris Lattner wrote:
>>
>> For the "generic" method that returns the sizeof, we may consider
>> having it return a variant type that wraps an integer primitive. The
>> variant could also have a flag indicating whether or the not the
>> sizeof returned is valid. This way we can have the generic method
>> return "unknown" for VLAs if clients just blindly call sizeof on VLA
>> types. For example:
>
> How about a really simple variant: int64_t :)
>
> Define -1 to be "invalid" and -2 to be "vla" and you're golden.
>
> -Chris
That's a nice solution because of its simplicity. One thing that I
like about the solution that I proposed is the extra checking done by
the type system, the automatic assertions, and a clear API to query
the sizeof value instead of checking for magic numbers (just use
methods: isVLA(), isValid(), etc.). Using a thin class also doesn't
cost us anything in terms of runtime overhead, although it will have a
negligible impact on compile time.
More information about the cfe-dev
mailing list