Is '(NULL + 1) - 1' valid C?

Doug Gwyn gwyn at smoke.BRL.MIL
Sat Aug 12 17:09:43 AEST 1989


In article <8908112140.AA00303 at euresis.eng.umd.edu> nero at eng.umd.edu (Oren L. Stern) writes:
>Assuming that "NULL + 1" is non-portable C, I am now wondering if it's
>valid to use NULL as an expression.  For example, is it valid to write:
>  for (ptr = head; ptr; ptr = ptr->next) {...}
>to traverse a linked list?

What is the logical connection between whether you can perform arithmetic
on the NULL macro, which wasn't the original issue anyway, and whether
or not the example loop you give works?

If you guys really don't understand how to use pointers, consult any
reasonable C programming textbook.  Kernighan & Ritchie explain it
quite clearly.  You may even find an analogous example there..



More information about the Comp.lang.c mailing list