Path: csiph.com!news.mixmin.net!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: Tim Rentsch Newsgroups: comp.lang.c Subject: Re: How About Disallowing Assignments In Expressions? Date: Wed, 14 Feb 2024 21:54:24 -0800 Organization: A noiseless patient Spider Lines: 46 Message-ID: <86jzn61ddb.fsf@linuxsc.com> References: <20240213192257.00002da6@yahoo.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Injection-Info: dont-email.me; posting-host="d6a0776853173adee93a90f6ecdad10b"; logging-data="3342924"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+fOaw0OSTwrpaR/X9GMrtJh8OVm3Gne6E=" User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.4 (gnu/linux) Cancel-Lock: sha1:R6o2onLzXDwze4Wt43tn4ieBuTI= sha1:EVPgbidpjre+L/pkVnN6wIWKnMc= Xref: csiph.com comp.lang.c:382504 Michael S writes: [.. should 'a += b += c;' be disallowed for style reasons? ..] > It's actually highly confusing for me as well. > For reasons I am not fully understand, it is interpreted as > a += (b += c) > which is obviously legal. > I don't understand why it isn't interpreted as > (a += b) += c > which is [a little less obviously] illegal. Here is another way to think about it. C (and many or most other languages) are fairly strict about what is allowed on the left-hand side of an assignment. For example, a + b += c; is not allowed. Neither is (a + b) += c; although the reasoning is a little different in the two cases, neither is allowed, because neither one makes sense. By analogy with the second example, the statement (a += b) += c; isn't allowed, because the left-hand side is wrong. So if we see a += b += c; it would be silly to parse it as (a += b) += c; because that's illegal. The only other way to parse it, viz., a += (b += c); passes the semantic prerequisites. Since it's the only way that makes sense, it seems natural that (without any parentheses) the syntax should reflect that.