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: Wed, 13 Mar 2019 15:24:48 -0700 Organization: None to speak of Lines: 31 Message-ID: References: <87lg1o9efx.fsf@bsb.me.uk> <1bh8cb93bi.fsf@pfeifferfamily.net> <86sgvqr96y.fsf@mailhub.linuxsc.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Injection-Info: reader02.eternal-september.org; posting-host="ef668bcb4e936841576656e0ca0b6672"; logging-data="22698"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/eqXezpEhuO8wVQ0bfZ3sZ" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux) Cancel-Lock: sha1:zYrDzSFTT5fe7+Ghv6BRGrnbIu4= sha1:iwWj9912fD794b+iwNxzWA9CL3w= Xref: csiph.com comp.lang.c:141944 Bart writes: [...] > People want to write code so that it is clear to everyone else. > Including those more used to other languages which have different > precedences. > > There is NO advantage to writing expressions whose meanings are > critically dependent on the relative precedences of &, | and ^. > > Plus, many operators just have the wrong precedence, so you want to > employ them in the most natural manner. And that requires parentheses. I mostly agree. I suspect we'd differ about how much readers can reasonably be expected to know, but let's not get into that. > Which, as a bonus, makes code more portable. In what sense is it more portable? If I write C code that depends on all 15 precedence levels, it's likely to be difficult for human readers to understand it, but every C compiler will parse it correctly. I've never heard of a C compiler having an operator precedence bug. It's just too easy to get it right. If you mean "portable" in the sense that it's easier to translate to a different language, that's hardly ever worth worrying about. (And a lot of languages uses the same precedence levels as C.) -- Keith Thompson (The_Other_Keith) kst-u@mib.org Will write code for food. void Void(void) { Void(); } /* The recursive call of the void */