SIZEOF

Gary M. Samuelson garys at bunker.UUCP
Sat Feb 9 00:32:44 AEST 1985


> 	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.

Your reasoning breaks down at the implicit assumption that passing
0 as an argument to a function constitutes an assignment.  It doesn't;
the compiler does not know the types of function arguments where the
function is called.  E.g., when you write foo(bar), the compiler
knows what "bar" is, but has no idea what type foo's formal parameter
has.

> It is also mentioned that "The mapping function... is intended to be
> unsurprising 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

Gary Samuelson



More information about the Comp.lang.c mailing list