offsets in structures.

Doug Gwyn <gwyn> gwyn at brl-tgr.ARPA
Sat Oct 20 06:19:34 AEST 1984


Although I see no particular use for the following piece of code,
I believe that it is supposed to be legal both now and in the ANSI
standard:

	char	*foo;

	foo -= (long)foo;	/* or (int) perhaps */
	/* foo now is NULL */

More importantly,

	char	*malloc(), *where;

	where = malloc( (unsigned)40 );

	subr( where );	/* check validity of `where' and does something */

Here a NULL pointer must be type-compatible with other pointers.  Using
a special "nil" pointer could easily get in the way here (subr() might
end up with special-case "nil"-handling in-line code every time its
parameter is used).

What more does using special "nil" get you than using a 0, apart from
hardware check against dereferencing NULL?  In any case, the hardware
check is unnecessary if you write your code correctly.  Are we all
hackers or are there some professional programmers out there?



More information about the Comp.lang.c mailing list