Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!utgpu!water!watmath!clyde!rutgers!ames!sdcsvax!ucbvax!decvax!ima!haddock!karl From: karl@haddock.UUCP Newsgroups: comp.lang.c Subject: Arithmetic on NULL (was: char (*a)[]) Message-ID: <1151@haddock.ISC.COM> Date: Wed, 16-Sep-87 20:36:42 EDT Article-I.D.: haddock.1151 Posted: Wed Sep 16 20:36:42 1987 Date-Received: Sat, 19-Sep-87 06:04:10 EDT References: <1459@cullvax.UUCP> <48400001@tub.UUCP> Reply-To: karl@haddock.ima.isc.com (Karl Heuer) Organization: Interactive Systems, Boston Lines: 18 In article <48400001@tub.UUCP> cabo@tub.UUCP writes: >While I agree that "char *p = 0; p++;" should not be allowed by the standard, >I see some benign applications for constant expressions involving null >pointers, e.g. > (char *)&((struct foo *)0)->bar - (char *)&((struct foo *)0)->baz In ANSI C, the correct way to write the above is "offsetof(struct foo, bar) - offsetof(struct foo, baz)". Since this is guaranteed to work, your example is not evidence of a need for NULL pointer arithmetic. Now, it may well be the case that "offsetof" is defined in to expand into the above mess, on machines where it happens to work. That's okay; the use is portable even though the implementation is not. I expect that machines with non-flat address spaces and weird representations of NULL may have to implement "offsetof" as a builtin. That's okay too. Karl W. Z. Heuer (ima!haddock!karl or karl@haddock.isc.com), The Walking Lint