"do ... while ((NULL + 1) - 1);" -- valid C?
Chris Torek
chris at mimsy.UUCP
Fri Aug 11 19:14:09 AEST 1989
>> while ((s = strchr(s, ',') + 1) - 1)
In article <826 at ruso.UUCP> wolfgang at ruso.UUCP (Wolfgang Deifel) writes:
>Why should NULL + 1 not be valid ??? NULL is a pointer with the value 0
>and you can add the integer 1 to it ....
NULL is not a pointer with the value 0, and 1 is not being added to
NULL here, but rather to a nil-pointer-to-char in the case in question.
NULL is a preprocessor macro; it expands to either an integral constant
zero (whose type is one of the integral types, e.g., int or short or long,
and whose value is zero) or to such a value cast to pointer-to-void
(whose type is pointer-to-void and whose value is unknowable).
A nil-pointer-to-char has type pointer-to-char and an ineffable value.
There is no way to talk about its value other than to say `it is a
nil pointer to char'. In particular, you cannot say what happens
when you add one to it.
--
In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept (+1 301 454 7163)
Domain: chris at mimsy.umd.edu Path: uunet!mimsy!chris
More information about the Comp.lang.c
mailing list