[cfe-dev] sizeof(sizeof(...))

Ted Kremenek kremenek at apple.com
Fri Dec 14 13:11:15 PST 2007

After thinking about this a little more, my understanding is that  
sizeof simply evaluates to a type of unsigned int, so  
sizeof(sizeof(...)) is equivalent to sizeof(unsigned int).  If anyone  
thinks this is wrong, please let me know.

On Dec 14, 2007, at 12:30 PM, Ted Kremenek wrote:

> Does anyone have any insights on the semantics of expressions of the
> form sizeof(sizeof(...))?  For example, the following is legal code:
> int baz(int x) {
>  typedef int a[f()];
>  return sizeof (sizeof(a[bar(x)]));
>         + sizeof(sizeof(x));
> }
> From the C99 standard (
>   "The sizeof operator yields the size (in bytes) of its operand,
> which may be an
>   expression or the parenthesized name of a type. The size is
> determined from the type of
>   the operand. The result is an integer. Ifthe type of the operand is
> a variable length array
>   type, the operand is evaluated; otherwise, the operand is not
> evaluated and the result is an
>   integer constant."
> I am having a little difficulty interpreting the (general) semantics
> of applying sizeof to sizeof.  Moreover, "sizeof (sizeof(a[bar(x)]))"
> does not cause bar() to be called, whereas (as expected)
> sizeof(a[bar(x)]) does.
> _______________________________________________
> cfe-dev mailing list
> cfe-dev at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev

More information about the cfe-dev mailing list