"do ... while ((NULL + 1) - 1);" -- valid C?
Conor P. Cahill
cpcahil at virtech.UUCP
Tue Aug 8 11:44:06 AEST 1989
In article <1043 at levels.sait.edu.au>, ccdn at levels.sait.edu.au (DAVID NEWALL) writes:
>
> 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.
NULL, in this case, is just a pointer that has the value 0. NULL + 1 is a valid
operations, however *(NULL+1) is not.
I wouldn't code the loop as you have displayed because one has to
spend time thinking about what the will is trying to do. A "better" method
would be something like:
do
...;
s = strchr(s,',');
while ( s++ != NULL );
More information about the Comp.lang.c
mailing list