Path: csiph.com!eternal-september.org!feeder.eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail From: Keith Thompson Newsgroups: comp.lang.c Subject: Re: "C's Biggest Mistake" Date: Sat, 07 Apr 2018 13:13:25 -0700 Organization: None to speak of Lines: 34 Message-ID: References: <9c7013a2-17bd-4f94-a378-1c45151d0d45@googlegroups.com> <2%LxC.241942$Oy5.103980@fx11.am4> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Injection-Info: reader02.eternal-september.org; posting-host="a514ab945b6e8c6b28a176a69904e725"; logging-data="30813"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18meuKaJ+KAXUAW/FK9y/az" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux) Cancel-Lock: sha1:TQnfuMW4oA2zz8XOVpuY6qdg93A= sha1:g4lT8WXZc3WrgNdgwjMzcNSKbBU= Xref: csiph.com comp.lang.c:128903 David Brown writes: [...] > But that would be a very weird way to write the code in C. Why would > you have a switch here? > > while (true) { > c = *p++; > if ((c >= 'A') && (c <= 'Z)) continue; > if ((c >= '0') && (c <= '9)) continue; > break; > } > > (There are many other ways to write it - that was just one example.) [...] Both your version and bartc's example (in his own language) using ranges are non-portable. The language guarantees that '0'..'9' are contiguous, but it makes no such guarantee for 'A'..'Z' or 'a'..'z'. And in fact in EBCDIC there are extra characters between 'A' and 'Z', and between 'a' and 'z'. (And depending on the application you might need to deal with letters other than the 52 Latin ones.) Incidentally, gcc supports case ranges as an extension, but it uses `...` rather than `..` (probably because `...` is an existing token). And the documentation warns the programmer to put spaces around the `...` symbol, because `1...5` would fail to parse. -- 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"