SIZEOF

J. Shapiro jss at sjuvax.UUCP
Wed Feb 6 18:42:44 AEST 1985


[Aren't you hungry...?]
	It occurs to me that the length of a pointer simply being required to
be constant (even within the same data type) presents problems. Many
microprocessors now implement span-dependent addressing, and if your
implementation allows passing of an array wholesale, and that array is
small, there is no reason why one shouldn't be able to optimize the pointer
size as being relative to some register variable which points to the
current function's bottom of passed data.

	Is this a problem in practice - are pointers in fact obliged to be the
same size everywhere, or am I missing something?

	On the topic of sizeof(int) == sizeof(int *), I refer you to K&R p.
210, which says:
	
		1. A pointer may be converted to any of the integral types long
		enough to hold it. Whether an int or a long is required is machine
		dependent.

		2. An object of integral type may be explicitly converted to a
		pointer...

Since compilers need to do type checking anyway, passing 0 instead of NULL
should always be valid.  Note that K&R says that assigning 0 to an integer
generates the appropriate NULL pointer.  This type conversion (it is
implied) is automagic, and thus there *is* a generic NULL, which is the
integer 0.

It is also mentioned that "The mapping function... is intended to be
undsurprising to those who know the addressing structure of the machine,"
which is a loophole big enough to fly a barn through.

Jon Shapiro
Haverford College



More information about the Comp.lang.c mailing list