New Features: ++(expr)
Richard A. O'Keefe
ok at quintus.UUCP
Sun Feb 14 17:40:50 AEST 1988
In article <681 at devon.UUCP>, paul at devon.UUCP (Paul Sutcliffe Jr.) writes:
> In article <1102 at bc-cis.UUCP> john at bc-cis.UUCP (John L. Wynstra) writes:
> > In article <386 at osupyr.UUCP> ddc at osupyr.UUCP (Don Comeau) writes:
> > > I think ++expr should be an expression which has the value expr+1
> > Yes, can you say redundant?
> Sure, ++expression is redundant. So is ++lvalue. If you dispise the
> redundancy, why have ++ and -- at all, since I can easily use
> lvalue = lvalue + 1
>or lvalue += 1
There is an important difference between
lvalue = lvalue+1;
and lvalue += 1;
The difference is that the lvalue is evaluated twice in the former,
and only once in the latter. Consider
*x++ = *x++ + 1;
-vs- *x++ += 1;
Prefix ++ and -- are redundant, because they can be simulated
exactly using +=, but postfix ++ and -- aren't. (Strictly speaking,
to be consistent with the other assignment operators, shouldn't the
simple assignment operator in C be ",="? Just kidding...)
The really horrible thing about the suggestion is that if ++(expr)
meant the same as (expr)+1 except for lvalues, we'd have
++(x) increments x, but
++(x+0) wouldn't.
I have seen too many bugs materialise in otherwise sensible
programs due to the "feature" of Fortran and PL/I that in
passing arguments to a procedure
x means pass the address of x, but
(x) means pass the address of a copy of x.
C has enough crannies for bugs to breed in without giving them
some more.
More information about the Comp.lang.c
mailing list