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

Wolfgang Deifel wolfgang at ruso.UUCP
Thu Aug 10 18:55:56 AEST 1989


ccdn at levels.sait.edu.au (DAVID NEWALL) writes:

>                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.

Why should NULL + 1 not be valid ??? NULL is a pointer with the value 0
and you can add the integer 1 to it ( but you cannot access *s in the case
strchr is NULL of course ).

    Wolfgang.



More information about the Comp.lang.c mailing list