neophyte's pointer question
Andrew Koenig
ark at rabbit.UUCP
Wed Apr 11 04:54:45 AEST 1984
If s is a character pointer then
*s++ = (s & 0x7f);
is definitely undefined, as the meaning of the "and" operator applied
to a pointer is undefined (i. e. implementation dependent). Perhaps the
question was intended this way: Is it OK to write:
*s++ = (*s & 0x7f);
The answer here is still no, because there is no guarantee as to
whether s will be incremented before or after the right-hand-side
is evaluated. If the author assumed that the right-hand-side would
be evaluated first, the result desired would be to turn off all but
the low-order seven bits of the character addressed by s and then
increment s. This can be done as follows:
*s++ &= 0x7f;
Alternatively, one can write:
*s = (*s & 0x7f); /* parens not really needed */
s++;
More information about the Comp.lang.c
mailing list