Path: csiph.com!eternal-september.org!feeder.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: Keith Thompson Newsgroups: comp.lang.c Subject: Re: Synthetic 'unless' keyword Date: Thu, 04 Aug 2016 10:23:44 -0700 Organization: None to speak of Lines: 36 Message-ID: References: <83245b54-cf15-4d82-9418-cf48ba3cb37b@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Injection-Info: mx02.eternal-september.org; posting-host="945944de09706c9b4e29b53c9d2efdc2"; logging-data="16703"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1//Y16R0ElwYyG+8NxwUd0T" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux) Cancel-Lock: sha1:Anl6vRF+uQ5J+sWfQOENWE/8dPo= sha1:vUBqBqVrng+y3DfiCPxzEPimpsw= Xref: csiph.com comp.lang.c:91659 supercat@casperkitty.com writes: > On Thursday, August 4, 2016 at 10:52:33 AM UTC-5, Keith Thompson wrote: >> One drawback of the `if (!expr)` form is that `!` is a single >> character that can sometimes be easy to miss. Adding a space: >> `if (! expr)` helps a bit. One nice thing about Perl is that you can >> write `not` rather than `!`. You can do the same in C with `#include >> `, but that's unfamiliar enough that I don't use it myself. > > IMHO, that's less of an issue than the fact that ! only binds to the first > term, rather than inverting the entire expression. Given a collection > of "if" statements some of which test affirmative conditions and some of > which test negative conditions, it becomes necessary to either use different > levels of nesting on positive and negative expressions, use doubled-up > parentheses on the positive expressions, or else add a redundant double- > invert on the positive ones. > > Extending the grammar by having "if" and "while" accept a > "conditional-expression" which is satisfied by either "(expression)" > or "!conditional-expression" would quite easily resolve that issue, > though I doubt the issue is a big enough problem to justify the change. So the meaning of ! x == y would differ depending on whether it appears as the condition for an "if" or "while" (or, presumably "for", or "do-while", or "?:") or in some other context. No thanks! -- Keith Thompson (The_Other_Keith) kst-u@mib.org Working, but not speaking, for JetHead Development, Inc. "We must do something. This is something. Therefore, we must do this." -- Antony Jay and Jonathan Lynn, "Yes Minister"