🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.lang.c
Article #1355

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

#1355
From: Dan Cross
Date: Fri, 06 Nov 2026 16:26
49 lines
3085 bytes
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, so that one
could write things like:

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

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.

	- Dan C.
Technical Details
Message-ID: <11ckv3c$d9l$1@reader1.panix.com>
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!panix!.POSTED.spitfire.i.gajendra.net!not-for-mail
References: <11ceoa2$85p3$3@dont-email.me>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!panix!.POSTED.spitfire.i.gajendra.net!not-for-mail
From: cross@spitfire.i.gajendra.net (Dan Cross)
Newsgroups: comp.lang.c
Subject: Re: Rationales for result type of operations using operators like '+='
Date: Fri, 6 Nov 2026 16:26:20 -0000 (UTC)
Organization: PANIX Public Access Internet and UNIX, NYC
Message-ID: <11ckv3c$d9l$1@reader1.panix.com>
References: <11ceoa2$85p3$3@dont-email.me>
Injection-Date: Fri, 6 Nov 2026 16:26:20 -0000 (UTC)
Injection-Info: reader1.panix.com; posting-host="spitfire.i.gajendra.net:166.84.136.80";
	logging-data="13621"; mail-complaints-to="abuse@panix.com"
X-Newsreader: trn 4.0-test77 (Sep 1, 2010)
Originator: cross@spitfire.i.gajendra.net (Dan Cross)