sizeof (int) - 1

Gary M. Samuelson garys at bunker.UUCP
Thu Oct 2 04:25:58 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

>> The unix compiler does it the second way, for when it sees the '-' it
       ------------- (speaking of ambiguous)
>> 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."

You're both partially right, and partially wrong.  The expression
would be ambiguous, if not for the disambiguating rule where the
compiler is not *assuming* that the minus sign is binary, but
*deciding* that it is.

Gary Samuelson



More information about the Comp.lang.c mailing list