if (p) ...
Guy Harris
guy at sun.uucp
Mon Oct 21 08:11:54 AEST 1985
> In fact, I've worked in an environment (PRIMOS and other Multics-style
> systems) with segmented addressing schemes (and demand-paged virtual
> memory) wherein the definition of a NULL pointer was any address in
> the designated-highest-possible segment (defined as octal 7777). Thus,
> for C to see a pointer as null required conversion from 7777/0 to 0 (or
> seg 0 loc 0, which is a valid address) and back again!
No, it didn't. The author of the C compiler may have thought so, but if
he/she did then somebody else should have been chosen to write the compiler.
On such a machine,
1) NULL should have been #defined as 0 (just like everywhere else)
and
2) the statement
if (p)
foo();
should have compiled into something like
compare_immediate p, #07777/0 # seg 7777, loc 0
beq around
subroutine_call foo
around:
> YEAH, a portable test is necessary that does not depend on NULL being ZERO.
The definition of the C language requires that NULL be ZERO (how many times
do people have to be told this?). The test
if (p)
is already portable enough, as is the test
if (p != 0)
and the test
if (p != NULL)
In the aforementioned class of machines, all three test should compile into
code like the code listed above.
Guy Harris
More information about the Comp.lang.c
mailing list