Frederick Gotham said:
sizeof has the same precedence as a cast, and they both bind from right to
left. The following won't compile for me with gcc:
int main(void)
{
sizeof(double)5;
return 0;
}
Has it got something to do with "globbing"?
Consider this:
sizeof(double)-5
There is a syntactic ambiguity in this type of expression. It could be
interpreted as three unary operators: negation, the cast (double)
and 'sizeof', successively applied to the value 5:
sizeof( (double)(-5) )
or it could be interpreted as a binaary subtraction whose
operands are sizeof(double) and 5:
(sizeof (double)) - 5
This ambiguous case is resolved quite arbitrarily by declaring that the
latter interpretation shall be used.
Now replace the minus with a plus:
sizeof(double)+5
By the same logic, this is interpreted as (sizeof(double)) + 5
The same logic is used to have
sizeof(double)5 interpreted as (sizeof(double))5
which is a syntax error.
This type of thing is why many people like to
include parentheses around the operand of sizeof regardless of
whether that operand is a type name or a data object. It makes it
clear what the intent of the expression really is.