What does sizeof without () do? [duplicate]

So if we look at the grammar for sizeof in the C99 draft standard section 6.5.3 Unary operators paragraph 1 it is as follows:

sizeof unary-expression
sizeof ( type-name )

There is a difference you can not use a type-name without parenthesizes and section 6.5.3.4 The sizeof operator paragraph 2 says(emphasis mine):

The sizeof operator yields the size (in bytes) of its operand, which may be an
expression or the parenthesized name of a type.[…]

For completeness sake you may wonder if we can use sizeof with an expression if we have parenthesizes and the answer is yes since a unary-expression can itself contain parenthesizes. The easiest way to see this would be to look section A.2.1 Expressions from the draft standard and work through the grammar like so:

unary-expression -> postfix-expression -> primary-expression -> ( expression )

Leave a Comment