New Features: ++(expr)
sean fagan
aeusesef at csuna.UUCP
Mon Feb 15 07:50:15 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:
>> > Since everyone else is suggesting their addition to C, here is one I
>> > think would be useful. Why are ++ and -- still limited to lvalues? I
>> > think ++expresion should be an expression which has the value
>> > expression+1.
They are limited to lvalues because ++ and -- are, respectively,
incrementors and decrementors. It makes no sense to increment an expression
(you can increment the value of it, but not the expression itself), whereas
incrementing an lvalue makes perfect sense.
[++lvalue is redundant]
> lvalue = lvalue + 1
> lvalue += 1
yeah, but then you have something like
val = .... lvalue++ .... lvalue++ .... lvalue++;
(they are, hopefully, different lvalues, but not necessarily)
Your way, you have to do
val = .... (lvalue += 1) .... (lvalue += 1) .... (lvalue += 1);
Hmm.. I think I'd take the ++ operators. Now, if we use ++(expr), we get
val = .... ++(a+b+c) ... ++(a+b+c) ... ++(a+b+c);
or
val = .... (a+b+c+1) ... (a+b+c+1) ... (a+b+c+1);
Same amount of typing (but less shifting on my keyboard). The only reason I
could see having the '++(expr)' is so that the '1' added would be multiplied
by the size of the expression. However, I've never had a need to do that,
and overloading this operator in such a foolish fashion is, well, foolish.
>Paul Sutcliffe, Jr.
>UUCP (smart): paul at devon.UUCP
-----
Sean Eric Fagan Office of Computing/Communications Resources
(213) 852 5742 Suite 2600
1GTLSEF at CALSTATE.BITNET 5670 Wilshire Boulevard
Los Angeles, CA 90036
{litvax, rdlvax, psivax, hplabs, ihnp4}!csun!csuna!aeusesef
More information about the Comp.lang.c
mailing list