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

DAVID NEWALL ccdn at levels.sait.edu.au
Tue Aug 8 00:20:31 AEST 1989


I want to scan a string with fields separated by commas.  To do this, I
wrote the following:
                do
                   ...
                while ((s = strchr(s, ',') + 1) - 1);

I've been told that this is not valid C because, in the case that there
are no more fields (commas), strchr() returns NULL; and NULL + 1 is not
valid.

Comments, anyone?


David Newall                     Phone:  +61 8 343 3160
Unix Systems Programmer          Fax:    +61 8 349 6939
Academic Computing Service       E-mail: ccdn at levels.sait.oz.au
SA Institute of Technology       Post:   The Levels, South Australia, 5095



More information about the Comp.lang.c mailing list