offsets in structures.

gwyn at brl-tgr.UUCP gwyn at brl-tgr.UUCP
Sat Oct 20 06:19:34 AEST 1984


Relay-Version: version B 2.10 5/3/83; site houxe.UUCP
Posting-Version: version B 2.10.2 9/18/84; site brl-tgr.ARPA
Message-ID: <5400 at brl-tgr.ARPA>
Date: Fri, 19-Oct-84 16:19:34 EDT

 <204 at rlgvax.Fri, 19-Oct-84 13:19:34 PDT
Organization: Ballistic Research Lab
Lines: 26

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