"do ... while ((NULL + 1) - 1);" -- valid C?

Bill Rust wjr at ftp.COM
Wed Aug 9 23:38:08 AEST 1989


In article <10684 at smoke.BRL.MIL> gwyn at brl.arpa (Doug Gwyn) writes:
>In article <961 at virtech.UUCP> cpcahil at 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). Since the while construct is relying on the
fact NULL is, in fact, 0, doing NULL + 1 - 1 is ok. I certainly wouldn't
recommend using it as a reference to memory. But, unless NULL is a 
reserved word to your compiler, the compiler sees 0 + 1 - 1 and that is
ok.

Bill Rust (wjr at ftp.com)



More information about the Comp.lang.c mailing list