[net.lang.c] neophyte's pointer question

ark@rabbit.UUCP (Andrew Koenig) (04/10/84)

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++;

hamilton@uiucuxc.UUCP (04/13/84)

#R:rabbit:-269200:uiucuxc:21000011:000:37
uiucuxc!hamilton    Apr 12 19:22:00 1984

what's wrong with masking addresses?