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

Ted Kremenek kremenek at apple.com
Fri Dec 14 12:30:59 PST 2007


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 (6.5.3.4):

   "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.



More information about the cfe-dev mailing list