Indeed.
The simple fact is that sizeof *is* an operator, whether anyone likes
it or not. You (that's a generic "you") can use all the parentheses
you like in your own code, but if you can't cope with "sizeof x", then
you can't cope with valid C.
If K&R had chosen to use, say, "$" rather than "sizeof" as the symbol
for this operator, we wouldn't be having this discussion.
That's open to question. The problem is that sizeof is a hack;
it is not an operator in the same way that operators such as + et
al are operators. (The fact that the standard calls sizeof an
operator is beside the point - the issue is not what the thing is
called but rather its intrinsic propertires.)
In effect, ordinary C operators are functions in disguise, i.e.
functions with special syntax. Their arguments are the values of
expressions; they "return" values within the C type system. C
does not have type valued variables; nonetheless sizeof has a
type as an "argument", either explicitly as in sizeof(int) or
implicitly as in sizeof(x). The fact that in some instances the
parentheses are not needed and in others it is required is a
hack.
Since sizeof (or $ if you want to call it that) requires
parentheses in some circumstance IMHO it would have made more
sense to call it a function (in the C sense of functions of
course) rather than an operator and always require parentheses.
Be that as it may, always using parentheses seems to me to be the
better policy because it is simple and consistent.
(There are C coding styles that I dislike, but I can deal with them,
and even use them if necessary. I don't question the motivation or
integrity of those whose opinions differ from mine.)
--
Keith Thompson (The_Other_Keith) <
[email protected]>
Nokia
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
Richard Harter, (e-mail address removed)
http://home.tiac.net/~cri,
http://www.varinoma.com
Save the Earth now!!
It's the only planet with chocolate.