sizeof() confusion
Henry Spencer
henry at zoo.toronto.edu
Sat Nov 17 15:13:45 AEST 1990
In article <1990Nov16.141352.22426 at dce.ie> ch at dce.ie (Charles Bryant) writes:
>> there are two distinct uses of sizeof:
>> sizeof unary_expression
>> sizeof ( type_name )
>
>That must make parsing it more difficult than if the parentheses were always
>required:
> sizeof (type_name) - 1
>since in other contexts "(type_name) - 1" would be an expression containing
>a cast.
Requiring parentheses wouldn't make any difference, since it's still legal
to wrap a unary expression in parentheses, so you can't tell from the
opening parenthesis which form is coming. What *would* be useful is if
casts began with something that *couldn't* begin a unary expression.
As it is, either you need to sneak a peek a bit further ahead, or you
get to write some contorted code that swallows the parenthesis and then
decides, based on the next token, whether it has cast-minus-leading-paren
or parenthesized-expression-minus-leading-paren. Definitely a nuisance,
and it's not the only such case in C.
--
"I don't *want* to be normal!" | Henry Spencer at U of Toronto Zoology
"Not to worry." | henry at zoo.toronto.edu utzoo!henry
More information about the Comp.lang.c
mailing list