So, if we look at the grammar for sizeof in the draft draft of C99 6.5.3 Unary operators, paragraph 1, it looks like this:
sizeof unary-expression sizeof ( type-name )
There is a difference in which you cannot use the type name without parentheses and section 6.5.3.4 The sizeof operator of the statement specified in clause 2 says (emphasis mine):
The sizeof operator gives the size (in bytes) of its operand, which can be an expression or a name in type brackets . [...]
For completeness, you may wonder if we can use sizeof with an expression if we have parentheses, and the answer is yes, because a unary expression can contain parentheses. The easiest way to see this is to look at section A.2.1 Expressions from the draft standard and work with the grammar as follows:
unary-expression -> postfix-expression -> primary-expression -> ( expression )
Shafik yaghmour
source share