Let's define our own NULL II
Chuck Karish
karish at denali.stanford.edu
Sat Jun 25 02:35:03 AEST 1988
In article <6821 at sigi.Colorado.EDU> swarbric at tramp.Colorado.EDU (Frank Swarbrick) writes:
>Someone already pointed out that ANSI has NULL defined in stddef.h. In Turbo C
>1.5 it is in both stdio.h and stddef.h. If I only need NULL I just include
>stddef.h. All that Turbo C's stddef does is typedefs size_t and ptrdiff_t,
>defines NULL (as 0 or 0L, depending on memory model) and declares errno as an
>external variable.
ANSI C requires that compilers allow headers to be #included
more than once, with the same result that would have been
produced by doing it once. Thus, <stdio.h> can #include <stddef.h>
without worrying about whether the programmer uses that header
a second time.
This doesn't work in all historical implementations. For example,
the IBM XENIX compiler complains about multiple definitions.
In addition, that system defined NULL to be (char *)0 (it doesn't
have void pointers). Lint and cc complain if 0 is used for NULL;
I think they say "illegal combination of pointer and integer"
for some reasonable constructs.
The pickiness of the XENIX compiler is often helpful. Programs
that run on it are usually very portable to other System V
environments.
Chuck Karish ARPA: karish at denali.stanford.edu
BITNET: karish%denali at forsythe.stanford.edu
UUCP: {decvax,hplabs!hpda}!mindcrf!karish
USPS: 1825 California St. #5 Mountain View, CA 94041
More information about the Comp.lang.c
mailing list