Path: csiph.com!eternal-september.org!feeder.eternal-september.org!nntp.eternal-september.org!.POSTED!not-for-mail From: Keith Thompson Newsgroups: comp.lang.c Subject: Re: Sort of trivial code challenge - may be interesting to you anyway Date: Sun, 08 Mar 2026 13:27:23 -0700 Organization: None to speak of Lines: 43 Message-ID: <87zf4ixe1g.fsf@example.invalid> References: <10n80sc$3soe4$1@dont-email.me> <86v7feei2e.fsf@linuxsc.com> <10o53k6$1i0ef$2@dont-email.me> <86ms0peby6.fsf@linuxsc.com> <10ockdh$3qpk6$1@dont-email.me> <10ocrjn$3qpk6$2@dont-email.me> <10od64s$3qpk6$4@dont-email.me> <86ikb9bmtw.fsf@linuxsc.com> <10oem5t$n5hk$1@dont-email.me> <86o6kz9zng.fsf@linuxsc.com> <10oi72k$1rss6$1@dont-email.me> <10oid0u$1u9aa$2@dont-email.me> <10ok1sl$2e7mc$1@dont-email.me> MIME-Version: 1.0 Content-Type: text/plain Injection-Date: Sun, 08 Mar 2026 20:27:24 +0000 (UTC) Injection-Info: dont-email.me; posting-host="5c88fe53569b4c210fbfbf7e6275a6a7"; logging-data="2856651"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18RG6w3XziUax7oL0wFDVc5" User-Agent: Gnus/5.13 (Gnus v5.13) Cancel-Lock: sha1:554IJUvjLe7yRn/gS84xcrz4CoY= sha1:tjd4YkTEhwg3jSlqE/lSp4OLiYs= Xref: csiph.com comp.lang.c:396873 DFS writes: [...] > Nested ternaries like this: > > c = square ? a1 : !hwc ? h*w : a3 > h*w ? h*w : a3; > > are harder to decipher at first glance than 3 or 4 levels of indented > if-then-elses. A nested ternary can be readable if you format it carefully, particularly if implements something similar to a linear if/else chain. I might write the above at: c = square ? a1 : !hwc ? h*w : a3 > h*w ? h*w : a3; or even: c = square ? a1 : !hwc ? h*w : a3 > h*w ? h*w : a3; (The second and third conditions could be combined with "||".) It could be rewritten as an if/else chain like this: if (square) c = a1; else if (!hwc) c = h*w; else if (a3 > h*w) c = h*w; else c = a3; > But all the decision-making in one short line is a thing of beauty. For certain values of "beauty". [...] -- Keith Thompson (The_Other_Keith) Keith.S.Thompson+u@gmail.com void Void(void) { Void(); } /* The recursive call of the void */