🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.lang.c
Article #1356

Re: Rationales for result type of operations using operators like '+='

#1356
From: Janis Papanagnou
Date: Fri, 06 Nov 2026 17:53
90 lines
5499 bytes
On 2026-11-06 17:26, Dan Cross wrote:
> In article <11ceoa2$85p3$3@dont-email.me>,
> Janis Papanagnou  <janis_papanagnou+ng@hotmail.com> wrote:
>> I just stumbled about something in "C" where I knew there was behavior
>> that other languages designed differently; specifically the "compound"
>> "and-becomes" operators (+=, -=, *=, /=, %=).
>>
>> I'm basically looking for substantial[*] rationales for two properties;
>> (a) that their result is an rvalue (and not an lvalue), and
>> (b) that their evaluation in cascades has right-associativity.
> 
> I'm afraid you're not going to find very much here.  Those
> operators were added (to B!) less out of choice and more out of
> necessity; as Dennis Ritchie put it in his C history paper from
> HOPL II:
> 
> |After the TMG version of B was working, Thompson rewrote B in
> |itself (a bootstrapping step). During development, he
> |continually struggled against memory limitations: each language
> |addition inflated the compiler so it could barely fit, but each
> |rewrite taking advantage of the feature reduced its size.  For
> |example, B introduced generalized assignment operators,
> |using `x=+y` to add `y` to `x`. The notation came from Algol 68
> |[Wijngaarden 75] via McIlroy, who had incorporated it into his
> |version of TMG.  (In B and early C, the operator was spelled
> |`=+` instead of `+=`; this mistake, repaired in 1976, was
> |induced by a seductively easy way of handling the first form in
> |B's lexical analyzer.)
> (https://www.nokia.com/bell-labs/about/dennis-m-ritchie/chist.html)
> 
> The implication here is that the mechanism was introduced to
> save space, versus the ceremony of, `i = i + 2;` and similar.
> 
> As to your specific questions, why make these Rvalues (or,
> rather, not lvalues) and why right-associative?  I suspect to
> match the semantics of an assignment expression,

Yes, I also think this was probably an underlying intention. And
this, the view as assignment - which is actually the most prominent
outlier in the zoo of [dyadic/"binary"] operators concerning its
right-associativity! - (and as opposed to a normal expression) also
contributes to the confusion some obviously have here and thus
consider another semantics - one that considers these op= as part of
a typical expression that are regularly evaluated from left to right
- as "inconsistent" despite being just the normal way to evaluate
expressions.

> so that one could write things like:
> 
> 	x = i += j++ * 3 + 5;

Yes, in "C" they like side-effects. Here we have two! It's strange
that people feel confused about the (simple!) Algol 68 semantics but
have no issues with such expressions. Rewritten without side effects

     i = i + j * 3 + 5;
     x = i;
     j++;

While the Algol 68 semantics with the chaining (returning the lvalue
of the LHS) is comparably clear; just "operating on the left-hand
item". Especially for folks who know the C++'s "cout operators" '<<'
(etc.) should have no issue understanding that simple concept I'd
have thought; it's also returning the LHS as lvalue so that it can
be "pipelined".

> 
> And so on.  If one considers `++` and `--` extensions of
> generalized assignmnet (and Ritchie suggests that they are in
> the HOPL paper), then this makes some sense as the semantics vis
> the expression's value differ depeneding on whether the operator
> is prefix or postfix.
> 
> I doubt this is particularly satisfying as an answer.

Thanks. Your answer actually is clearer and more to the point than
other posts since it avoids subjective dislikes, personal confusions,
or purported inconsistencies.

I certainly don't prefer the "C" way, but I've got some feeling now
why it became what it is. And that was the intention of my question.

The active defenders of C's implementation actually also contributed
since they made it quite obvious that there appears to be no clear
and convincing reason or substantial advantage of the design of this
language detail, rather the opposite, that there would be advantages
but in their opinion just not worthwhile. So thanks to those as well.

Janis
Technical Details
Message-ID: <11cl47f$23539$7@dont-email.me>
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!eternal-september.org!feeder.eternal-september.org!nntp.eternal-september.org!.POSTED!not-for-mail
References: <11ceoa2$85p3$3@dont-email.me> <11ckv3c$d9l$1@reader1.panix.com>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!eternal-september.org!feeder.eternal-september.org!nntp.eternal-september.org!.POSTED!not-for-mail
From: Janis Papanagnou <janis_papanagnou+ng@hotmail.com>
Newsgroups: comp.lang.c
Subject: Re: Rationales for result type of operations using operators like
 '+='
Date: Fri, 6 Nov 2026 18:53:51 +0100
Organization: A noiseless patient Spider
Lines: 90
Message-ID: <11cl47f$23539$7@dont-email.me>
References: <11ceoa2$85p3$3@dont-email.me> <11ckv3c$d9l$1@reader1.panix.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Fri, 06 Nov 2026 17:53:52 +0000 (UTC)
Injection-Info: dont-email.me;
	logging-data="2200681"; mail-complaints-to="abuse@eternal-september.org";	posting-account="U2FsdGVkX1+ial01OztxC7UrwGwf7b2C"; posting-host="a1c3eccefbcc1d6f648cf481fadc4299"
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:GtB8saVEIy+de3CVmj4qK0oX2WY= sha256:/nrRPhXGGD1vn2ZbU8mhc5kJlwENqWJSzCqrvyCl+OQ=
	sha1:sPxqDVBc2VOY7AoZrueYQ6N/egg= sha256:PbYLFi0me99rFkR1gRewXOKCSU1eMzlNFNWyXW7PVR4=
Content-Language: en-US
In-Reply-To: <11ckv3c$d9l$1@reader1.panix.com>