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, 21 Feb 2024 01:35:33 -0800 Organization: A noiseless patient Spider Lines: 54 Message-ID: <86msruw462.fsf@linuxsc.com> References: <87il2s9fdj.fsf@nosuchdomain.example.com> <86wmr6z0zg.fsf@linuxsc.com> <87ttm5ieqp.fsf@bsb.me.uk> <87v86kdmor.fsf@bsb.me.uk> <875xyje60h.fsf@bsb.me.uk> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Injection-Info: dont-email.me; posting-host="c2d56115d1a51f86374d36f48015b9bf"; logging-data="3206051"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19aFFEVLliltf8AIRQSBECfGbYOt3QUmpA=" User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.4 (gnu/linux) Cancel-Lock: sha1:KRXKdN20Z5SHFFW96eE/Q9m4cgA= sha1:BX+ClwdPAQNhuaovtEteCyKDKP8= Xref: csiph.com comp.lang.c:382880 Ben Bacarisse writes: > [...] > >> On 20/02/2024 01:05, Ben Bacarisse wrote: >> >>> Mike Terry writes: >>> [...] >>> Your example shows why I never liked this sort of "help". >>> Remembering where to start and what order to label the quadrants >>> is harder (for me) than knowing how trig functions work. >> >> Same for me. The trick to getting the signs of sins right is to >> think of circles, not triangles, when doing trig. Then it is all >> completely obvious. >> >>> Now, can we find a good mnemonic for C's operator precedence >>> levels? Extra credit if left/right associativity is also >>> covered. (Few! On topic again.) [...] > For me, pretty much the only one I'd have to look up (though only > in a year or two, since I've recently been reminded!) is ^ vs |. There are different kinds of memory aids. The ones that tend to work for me are those with some semantic content, not just rote memorization or via some cryptic acronym. This idea is similar to the first two paragraphs quoted above. For the bitwise logical operators, an example of the kind of memory aid I find helpful is as follows. The result of an & operator can have fewer bits on than its operands, but never more; The result of an | operator can have more bits on than its operands, but never fewer; The result of an ^ operator can have either fewer bits on or more bits on than its operands (or possibly the same number), depending on the values of the operands. Hence it makes sense to put ^ between & and |, and that is indeed where it is in C's precedence hierarchy -- fewer, fewer or more, more -- & ^ |. (Of course I expect & binds more tightly than |, as is conventional in mathematics and hardware design, etc.) I can't say I ever had a problem with the relative precedences of the bitwise logical operators, but this description probably did help cement it for me.