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

Oliver Hunt oliver at apple.com
Fri Dec 14 14:36:59 PST 2007


On 14/12/2007, at 2:21 PM, Bill Wendling wrote:

> Well, the standard says to "integer" type, so probably not unsigned.
> But that's my understanding of it. Though I don't believe that sizeof
> should be evaluating the expression...

Indeed, my understanding was that sizeof expr merely evaluated the  
type of the expression, not the expression itself.

--Oliver

>
> -bw
>
> On Dec 14, 2007 1:11 PM, Ted Kremenek <kremenek at apple.com> wrote:
>> 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 (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.
>>> _______________________________________________
>>> cfe-dev mailing list
>>> cfe-dev at cs.uiuc.edu
>>> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
>>
>> _______________________________________________
>> cfe-dev mailing list
>> cfe-dev at cs.uiuc.edu
>> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
>>
> _______________________________________________
> 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