& operator
Kenneth Almquist
ka at hou3c.UUCP
Tue Dec 20 01:02:29 AEST 1983
>From Steven M. Haflich:
The variable `in' is indeed modified at the same time that
the postfix ++ is evaluated, not after the entire statement.
Consider:
char *in = "123";
if (*in++ == *in++) ... ; /* ought never be true */
Although except for the `,' `&&' and `||' operators C explicitly does
not specify order of evaluation within expressions (and therefore
expressions which use multiple `++' and `--' operators on the same
variable are usually crocky) I see no reason why the above conditional
could not be used to check whether the first two characters of a string
(known to be at least length two) are the same.
Although there may be some support for this view in the C manual, this is not
the interpretation of the people in Murrey Hill. Be warned that C compilers
may not always perform the increment immediately after fetching the value of
the variable. Thus the above statement could be compiled as
temp = in; /* save value of "in" before incrementing it */
in += 2; /* perform both post-increments with one addition */
if (*temp = *temp) ... ;
Kenneth Almquist
More information about the Comp.lang.c
mailing list