sizeof (int) - 1

BEATTIE vedm at hoqam.UUCP
Tue Sep 30 22:49:25 AEST 1986


> 
> It is interesting that the expression
> 	sizeof (int) - 1
> is ambiguous in C, for it can be parsed as
> 	sizeof ((int)(- 1))
> or as
> 	(sizeof(int)) - 1
> 
> Think about it!
> 
> The unix compiler does it the second way, for when it sees the '-' it
> sets the precedence for that character ASSUMING it will be used as a
> binary operator.

There is nothing ambiguous about it.
K&R p188:
"The construction   sizeof(type)  is taken to be a unit, so the
expression  sizeof(type)-2  is the same as (sizeof(type))-2."
Tom.
...!{decvax | ucbvax}!ihnp4!hoqax!twb



More information about the Comp.lang.c mailing list