sizeof() confusion

Doug Gwyn gwyn at smoke.brl.mil
Sun Nov 18 00:52:12 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 ...

Yes, but this is necessary since C has "always" (actually, just for a long
time) had those two distinct usages of "sizeof".

Note that most published precedence tables for C operators, including K&R's,
get this wrong.  Using an example similar to the one you gave:

	sizeof ( short ) - 1
K&R's chart (p. 49 or 53, depending on edition) would have one parse this as
	sizeof ((short) (- 1))
whereas the only valid parse according to the C standard (and all existing
compilers of which I am aware) is
	(sizeof (short)) - 1
which has a different value.  



More information about the Comp.lang.c mailing list