SIZEOF
Peter Curran
peterc at ecr.UUCP
Wed Jan 23 01:54:17 AEST 1985
Of course, C SHOULD be defined to allow sizeof(int) != sizeof(int *).
However, due to one point in the Reference Manual, and K&R (and, I assume,
the standard, although I haven't checked), they are actually required to
be equal. The problem is that "0" is defined to be the Null pointer
constant. When "0" is passed as a parameter to a function, the compiler
cannot tell whether an int or an int * is intended. The effect of this is
that sizeof(int) must equal sizeof(int *), and even more, the value of the
Null address constant must be bit-for-bit identical to the value of ((int) 0).
Of course, many compilers do not conform to this requirement. The problem
can be avoided by, for example, always using (say) NULL as the Null
address constant, where NULL is #defined as something like ((char *) 0).
Doing so conforms to the Reference Manual, but not doing so also conforms
(and of course many, if not most, C programs don't follow this practice).
The real solution, of course, would be to introduce a new keyword, say "null",
which represents the Null address constant, with an implementation-
defined value. However, I doubt that that will ever come about.
Anyone who has made much effort at porting C code has no doubt encountered
this problem, but I don't think it is as well known as it should be.
More information about the Comp.lang.c
mailing list