nero@eng.umd.edu (Oren L. Stern) (08/12/89)
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? If not, I've got a lot of "portable" code to rewrite...:-) Oren Stern (nero@hellcat.eng.umd.edu)
gwyn@smoke.BRL.MIL (Doug Gwyn) (08/12/89)
In article <8908112140.AA00303@euresis.eng.umd.edu> nero@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..