printf() code size using Astartup.obj and AMIGA.LIB only

Chris Torek chris at umcp-cs.UUCP
Thu Jul 10 03:38:56 AEST 1986


In article <951 at jade.BERKELEY.EDU> mwm at eris.UUCP () writes:
>Also, if foo is a pointer type, the test (!foo) is wrong. NULL doesn't
>have to be zero.

(Old ground again. . . .)

NULL *does* have to be zero, and the test is not wrong.

Any null pointer must compare equal to the integer constant zero.
Any null pointer may contain a non-zero bit pattern.  Do you
understand the difference?  (If so, stop reading now.)

The difference is that the integer constant zero is only a zero
before compilation.  There is no conceptual reason that it cannot
mutate in the process of code generation.  For example, consider
a Vax compiler that uses the bit pattern 0xc0000000 as the null
pointer (0xc0000000 is an illegal address on a Vax).  The compiler
might turn this:

	register char *p = 0;

	...
	if (!p) ...

into this:

	movl	$0xc0000000,r11		# p = 0
	...
	cmpl	$0xc0000000,r11		# if (!p)
	jneq	L70			# branch if p == 0
	...

The same compiler would also generate different code for

	long t, time(); t = time(0);

and

	long t, time(); t = time((long *)0);

The former might generate the following:

	pushl	$0			# 0
	calls	$1,_time
	movl	r0,-4(fp)

and the latter:

	pushl	$0xc0000000		# (long *)0
	calls	$1,_time
	movl	r0,-4(fp)

Now do you see the difference?
-- 
In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept (+1 301 454 1516)
UUCP:	seismo!umcp-cs!chris
CSNet:	chris at umcp-cs		ARPA:	chris at mimsy.umd.edu



More information about the Comp.lang.c mailing list