I'm confused (Re: What C compilers have non-zero null pointers?)

Chip Salzenberg chip at tct.uucp
Fri Jul 27 04:35:19 AEST 1990


According to scs at adam.mit.edu (Steve Summit):
>rja <rja at edison.cho.ge.com> writes:
>>[NULL] is broken on several widely
>>used C compilers for the Intel segmented architecture.
>
>It wouldn't hurt if you named names.

I think he's talking about Turbo C and Microsoft C, which of course
are not broken (with respect to NULL, anyway).

In a portable program, any pointer may be compared for EQUALITY with
NULL.  Microsoft and Borland handle this case correctly.

However, in a portable program, no pointer may be compared for
RELATIVE MAGNITUDE with NULL.  Attempting to do so under Microsoft or
Turbo C will result in a comparison of the segment offset, but not the
segment selector.

Why is this done?  Efficiency.  Is it broken?  No.  Read on...

The ANSI C standard does not guarantee that comparisons of magnitude
with NULL will do anything meaningful.  Comparisons of magnitude are
only valid within a single object (structure or array), and by
definition, NULL cannot point to any object.

By coincidence, comparisons of magnitude with NULL work on many
architectures.  The '286 isn't one of them.
-- 
Chip Salzenberg at ComDev/TCT     <chip at tct.uucp>, <uunet!ateng!tct!chip>



More information about the Comp.lang.c mailing list