Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.c > #385562
| From | Keith Thompson <Keith.S.Thompson+u@gmail.com> |
|---|---|
| Newsgroups | comp.lang.c |
| Subject | Re: Interval Comparisons |
| Date | 2024-06-04 15:29 -0700 |
| Organization | None to speak of |
| Message-ID | <871q5c1gwe.fsf@nosuchdomain.example.com> (permalink) |
| References | <v3merq$b1uj$1@dont-email.me> <v3mu14$dhe9$1@dont-email.me> |
Thiago Adams <thiago.adams@gmail.com> writes:
> On 04/06/2024 04:14, Lawrence D'Oliveiro wrote:
>> Would it break backward compatibility for C to add a feature like this
>> from Python? Namely, the ability to check if a value lies in an interval:
>> def valid_char(c) :
>> "is integer c the code for a valid Unicode character." \
>> " This excludes surrogates."
>> return \
>> (
>> 0 <= c <= 0x10FFFF
>> and
>> not (0xD800 <= c < 0xE000)
>> )
>> #end valid_char
>
> See Chaining Comparisons
> https://www.open-std.org/JTC1/SC22/WG21/docs/papers/2018/p0893r0.html
>
> https://medium.com/@barryrevzin/chaining-comparisons-seeking-information-from-the-audience-abec909a1366
>
> I don't know what are the current status of this proposal.
That's a proposal for C++.
One interesting piece of information is that the authors did some research
on existing code:
"""
To that end, we created a clang-tidy check for all uses of chained
comparison operators, ran it on many open source code bases, and
solicited help from the C++ community to run it on their own. The check
itself casts an intentionally wide net, matching any instance of a @ b @
c for any of the six comparison operators, regardless of the types of
these underlying expressions.
Overall, what we found was:
- Zero instances of chained arithmetic comparisons that are correct
today. That is, intentionally using the current standard behavior.
- Four instances of currently-erroneous arithmetic chaining, of the
assert(0 <= ratio <= 1.0); variety. These are bugs that compile today
but don’t do what the programmer intended, but with this proposal would
change in meaning to become correct.
- Many instances of using successive comparison operators in DSLs that
overloaded these operators to give meaning unrelated to comparisons.
"""
I presume they searched only C++ code, but I'd expect similar results
for C.
As indicated above, such a change would quietly break any existing
code that uses something like `a < b < c` that's intended to mean
`(a < b) < c`, but it would quietly *fix* any code that uses `a < b < c`
under the incorrect assumption that the comparisons are chained.
(Though the latter code will not have been tested under the new semantics.)
--
Keith Thompson (The_Other_Keith) Keith.S.Thompson+u@gmail.com
void Void(void) { Void(); } /* The recursive call of the void */
Back to comp.lang.c | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Interval Comparisons Lawrence D'Oliveiro <ldo@nz.invalid> - 2024-06-04 07:14 +0000
Re: Interval Comparisons David Brown <david.brown@hesbynett.no> - 2024-06-04 10:58 +0200
Re: Interval Comparisons Mikko <mikko.levanto@iki.fi> - 2024-06-04 12:13 +0300
Re: Interval Comparisons David Brown <david.brown@hesbynett.no> - 2024-06-04 13:02 +0200
Re: Interval Comparisons bart <bc@freeuk.com> - 2024-06-04 12:23 +0100
Re: Interval Comparisons David Brown <david.brown@hesbynett.no> - 2024-06-04 15:24 +0200
Re: Interval Comparisons bart <bc@freeuk.com> - 2024-06-04 15:16 +0100
Re: Interval Comparisons David Brown <david.brown@hesbynett.no> - 2024-06-04 17:40 +0200
Re: Interval Comparisons scott@slp53.sl.home (Scott Lurndal) - 2024-06-04 15:27 +0000
Re: Interval Comparisons bart <bc@freeuk.com> - 2024-06-04 16:58 +0100
Re: Interval Comparisons Michael S <already5chosen@yahoo.com> - 2024-06-04 19:25 +0300
Re: Interval Comparisons bart <bc@freeuk.com> - 2024-06-04 17:54 +0100
Re: Interval Comparisons Lawrence D'Oliveiro <ldo@nz.invalid> - 2024-06-05 03:29 +0000
Re: Interval Comparisons Mikko <mikko.levanto@iki.fi> - 2024-06-04 16:11 +0300
Re: Interval Comparisons Janis Papanagnou <janis_papanagnou+ng@hotmail.com> - 2024-06-04 15:42 +0200
Re: Interval Comparisons Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2024-06-04 14:04 -0700
Re: Interval Comparisons bart <bc@freeuk.com> - 2024-06-04 11:39 +0100
Re: Interval Comparisons Thiago Adams <thiago.adams@gmail.com> - 2024-06-04 08:32 -0300
Re: Interval Comparisons Bonita Montero <Bonita.Montero@gmail.com> - 2024-06-04 13:37 +0200
Re: Interval Comparisons Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2024-06-04 15:29 -0700
Re: Interval Comparisons Blue-Maned_Hawk <bluemanedhawk@invalid.invalid> - 2024-06-04 11:41 +0000
Re: Interval Comparisons Michael S <already5chosen@yahoo.com> - 2024-06-04 15:17 +0300
Re: Interval Comparisons Lawrence D'Oliveiro <ldo@nz.invalid> - 2024-06-04 23:12 +0000
Re: Interval Comparisons bart <bc@freeuk.com> - 2024-06-05 00:22 +0100
Re: Interval Comparisons Lawrence D'Oliveiro <ldo@nz.invalid> - 2024-06-05 01:30 +0000
Re: Interval Comparisons bart <bc@freeuk.com> - 2024-06-06 19:48 +0100
Re: Interval Comparisons Lawrence D'Oliveiro <ldo@nz.invalid> - 2024-06-06 22:54 +0000
Re: Interval Comparisons bart <bc@freeuk.com> - 2024-06-07 01:52 +0100
Re: Interval Comparisons Lawrence D'Oliveiro <ldo@nz.invalid> - 2024-06-07 02:17 +0000
Re: Interval Comparisons Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2024-06-06 20:53 -0700
Re: Interval Comparisons Lawrence D'Oliveiro <ldo@nz.invalid> - 2024-06-07 04:25 +0000
Re: Interval Comparisons David Brown <david.brown@hesbynett.no> - 2024-06-07 11:22 +0200
Re: Interval Comparisons Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2024-06-07 02:55 -0700
Re: Interval Comparisons David Brown <david.brown@hesbynett.no> - 2024-06-07 13:04 +0200
Re: Interval Comparisons Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2024-06-07 11:57 -0700
Re: Interval Comparisons David Brown <david.brown@hesbynett.no> - 2024-06-08 17:42 +0200
Re: Interval Comparisons bart <bc@freeuk.com> - 2024-06-07 11:28 +0100
Re: Interval Comparisons Lawrence D'Oliveiro <ldo@nz.invalid> - 2024-06-07 10:45 +0000
Re: Interval Comparisons Michael S <already5chosen@yahoo.com> - 2024-06-07 14:51 +0300
Re: Interval Comparisons David Brown <david.brown@hesbynett.no> - 2024-06-07 13:17 +0200
Re: Interval Comparisons bart <bc@freeuk.com> - 2024-06-07 13:20 +0100
Re: Interval Comparisons David Brown <david.brown@hesbynett.no> - 2024-06-09 13:26 +0200
Re: Interval Comparisons bart <bc@freeuk.com> - 2024-06-10 16:33 +0100
Re: Interval Comparisons David Brown <david.brown@hesbynett.no> - 2024-06-10 17:56 +0200
Re: Interval Comparisons scott@slp53.sl.home (Scott Lurndal) - 2024-06-07 14:00 +0000
Re: Interval Comparisons Lawrence D'Oliveiro <ldo@nz.invalid> - 2024-06-07 10:42 +0000
csiph-web