Article View: comp.lang.c
Article #1320Rationales for result type of operations using operators like '+='
From: Janis Papanagnou
Date: Wed, 04 Nov 2026 07:53
Date: Wed, 04 Nov 2026 07:53
36 lines
2713 bytes
2713 bytes
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. It might have been that it appeared not as serious to me because I had mostly used C++, and I may have (wrongly!) assumed that "C" behaves the same way. But sadly, no, they differ here. i += 2 *= 3 -= 5 %= 11; // impossible in C and C++ (((i += 2) *= 3) -= 5) %= 11; // impossible in C, possible in C++ But C++ still requires parentheses because of the right-associativity. (I suppose the rvalue to lvalue semantical design variant in C++ was to facilitate such cascades? And the left-associativity was maybe considered to be too drastic a change compared to the (partly) inherited "C" design? But my primary question here is about the "C" design rationale!) Note: My question is not about possible workarounds. (I know them.) Janis [*] I emphasized "substantial" because what the Google AI "explained" to me wasn't at all convincing. PS: Algol 68 (for example) had also a left-associativity which allows i +:= 2 *:= 3 -:= 5 %*:= 11 and given that the "C" authors knew that language but deviated from that paragon there must (or might) have been some thoughts about why it is as it is?
Technical Details
Message-ID:
<11ceoa2$85p3$3@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-mailShow 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: Rationales for result type of operations using operators like '+=' Date: Wed, 4 Nov 2026 08:53:38 +0100 Organization: A noiseless patient Spider Lines: 36 Message-ID: <11ceoa2$85p3$3@dont-email.me> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Injection-Date: Wed, 04 Nov 2026 07:53:38 +0000 (UTC) Injection-Info: dont-email.me; logging-data="268067"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18wuK+u6YGd97M234zIGtV2"; posting-host="8dc652b2ce3e2311159d2e8d1571c9b6" User-Agent: Mozilla Thunderbird Cancel-Lock: sha1:8TYiBEdTdK32cS5pdHk4eOvyFRU= sha256:+6mn90ccYW+AgU4/qFWVBw/9MMolAKi2O0d+/6wFTdw= sha1:xrK0swzdWhHDbOTOeJDqyX31DIA= sha256:3BPrPpw4zi0HJsG6jUjv3EyH6U/3YN4Vglfqc6cgRvQ= Content-Language: en-US