Use of NULL in UNIX & C (Was: Microport Unix -- Large Model Problems)

John Chambers jc at cdx39.UUCP
Sat Dec 6 02:34:29 AEST 1986


> Newsgroups: net.lang.c

[Gee, I wish people wouldn't redirect followups to non-existent newsgroups! :-]

This has been a constant hassle in porting code to 68000s, 
because many C compilers give me 16-bit ints and 32-bit
pointers.  One of the most common examples:
	l = time(NULL);
gets a Segmentation Fault, because the NULL is #defined as
just 0, and only 16 bits of zeroes are stacked.  The routine
fetches them plus 16 bits of garbage and tries to store the
clock value there.

In general, it might be a good idea to define a bunch of nulls:
	#define NULLI ((int)0)
	#define NULLL ((long)0)
	#define NULLP ((char*)0)
	#define NULLR ((real)0)
	...

Now if there were only a way to ensure proper alignment in
printf() formats.  I've heard a rumor that there's a version
of lint somewhere that has an option to check for this.  The
2.11 news release bombed spectacularly here due to some printfs 
like:
	printf("... %x ... %s ...",p1,p2);

When I changed it to %lX it worked just fine.
-- 
	John M Chambers			Phone: 617/364-2000x7304
Email: ...{adelie,harvax,inmet,mcsbos,mit-eddie,mot[bos],rclex}!cdx39!{jc,news,root,usenet,uucp}
Smail: Codex Corporation; Mailstop C1-30; 20 Cabot Blvd; Mansfield MA 02048-1193



More information about the Comp.lang.c mailing list