Path: csiph.com!eternal-september.org!feeder.eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail From: Keith Thompson Newsgroups: comp.lang.c Subject: Re: Remembering C's operator precedence rules Date: Sat, 09 Mar 2019 14:17:57 -0800 Organization: None to speak of Lines: 43 Message-ID: References: <87lg1o9efx.fsf@bsb.me.uk> <87ftrvaglt.fsf@bsb.me.uk> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Injection-Info: reader02.eternal-september.org; posting-host="27fa8bf6c916b83812acd4d11f7fc6c5"; logging-data="6671"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+QNJW4V0WXByTJ+e97yjSB" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux) Cancel-Lock: sha1:qyRkK/poIghCuRJYEmrZZxGI+pE= sha1:ebMtLxbs99PAb+9dzAMX/mwrSik= Xref: csiph.com comp.lang.c:141854 Ben Bacarisse writes: > Keith Thompson writes: >> Ben Bacarisse writes: >> [...] >>> Within the big block of relational operators, another grouping that >>> looks odd at first is that == and != have their own precedence level >>> just below <, >, <= and >=. This is another case that it's probably >>> wise to assume not everyone knows, but /you/ might remember it if you >>> consider that == and != make sensible logical connectives, rather like >>> && and ||. For example, to test if four variables are in order -- >>> either ascending or descending -- you can write >>> >>> a <= b == b <= c == c <= d >>> >>> Compare that with >>> >>> a <= b && b <= c && c <= d >>> >>> for a single order. >> >> I think you forgot about associativity. >> x == y == z >> means >> (x == y) == z >> not >> (x == y) && (y == z) > > Thanks. I should have looked for a better example as this one gets > messy when corrected. Do you know of an example that would motivate the > otherwise rather surprising separation between relational an equality > operators? You could use the same method to determine whether 3 values are in either ascending or descending order: a <= b == b <= c It just breaks down when you need more than one "==" operator. (I'd parenthesize that myself.) -- Keith Thompson (The_Other_Keith) kst-u@mib.org Will write code for food. void Void(void) { Void(); } /* The recursive call of the void */