Path: utzoo!utgpu!watmath!att!dptg!rutgers!cs.utexas.edu!uunet!ginosko!aplcen!haven!adm!smoke!gwyn From: gwyn@smoke.BRL.MIL (Doug Gwyn) Newsgroups: comp.lang.c Subject: Re: "do ... while ((NULL + 1) - 1);" -- valid C? Message-ID: <10691@smoke.BRL.MIL> Date: 9 Aug 89 20:35:48 GMT References: <1043@levels.sait.edu.au> <961@virtech.UUCP> <10684@smoke.BRL.MIL> <696@ftp.COM> Reply-To: gwyn@brl.arpa (Doug Gwyn) Organization: Ballistic Research Lab (BRL), APG, MD. Lines: 26 In article <696@ftp.COM> wjr@ftp.UUCP (Bill Rust) writes: -In article <10684@smoke.BRL.MIL> gwyn@brl.arpa (Doug Gwyn) writes: ->In article <961@virtech.UUCP> cpcahil@virtech.UUCP (Conor P. Cahill) writes: ->>NULL + 1 is a valid operations, ... ->No! -In my experience, NULL is always defined using the preprocessor line -"#define NULL 0" (or 0L). That's not always true, but anyway it's irrelevant... -Since the while construct is relying on the fact NULL is, in fact, 0, -doing NULL + 1 - 1 is ok. The code example was adding 1 to the return value from strchr(). strchr() does not return a preprocessor macro; it returns a null macro (when it doesn't return a pointer to a valid char object). You are not allowed to add 1 to a null pointer. If you happen to get away with it, you're just lucky; it's not correct code. In any event, if you rely on NULL being defined (for example in) as the source character string "0", then you're asking for trouble, since it can be defined as any valid form of null pointer constant, including for example "((void*)0)". Indeed, it's rather expected that standard- conforming implementations are more likely to choose the latter form. Your program may suddenly stop working when a new release of the compiler is installed, or when you port it to another environment.