Source-Changes-D archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
Re: The --> "operator" (was: Re: CVS commit: src/sys/uvm)
> Date: Wed, 8 Jul 2026 07:46:38 -0700 (PDT)
> From: Hisashi T Fujinaka <htodd%twofifty.com@localhost>
>
> The fact that the people I trust to know C better than I do are
> discussing this "operator" means it really isn't that obvious and should
> probably not be used. Overly clever code is hard to read.
I generally agree about `overly clever' code. But you haven't said
which alternative you prefer for iterating safely in reverse over
array indices the half-open interval [0,N)!
Some of the following options are correct for _only_ signed
arithmetic, some of the following options are correct for both signed
and unsigned arithmetic, and some of the following options are broken
for both.
So, quiz, to be self-timed: Can you work out in 60 seconds or less
which ones are which?
I can tell you in a second _one_ of them is definitely correct, and
for _every other one_ it'll take me at least a few seconds if not a
few minutes to think about. And once we've had this conversation
once, I bet you'll have the same experience.
for (i = N - 1; --i > 0;} { ... i - 1 ... }
for (i = N - 1; --i > 0;} { ... i ... }
for (i = N - 1; --i >= 0;} { ... i - 1 ... }
for (i = N - 1; --i >= 0;} { ... i ... }
for (i = N - 1; i --> 0;) { ... i - 1 ... }
for (i = N - 1; i --> 0;) { ... i ... }
for (i = N - 1; i > 0; i--} { ... i - 1 ... }
for (i = N - 1; i > 0; i--} { ... i ... }
for (i = N - 1; i >= 0; i--} { ... i - 1 ... }
for (i = N - 1; i >= 0; i--} { ... i ... }
for (i = N - 1; i-- > 0;} { ... i - 1 ... }
for (i = N - 1; i-- > 0;} { ... i ... }
for (i = N - 1; i-- >= 0;} { ... i - 1 ... }
for (i = N - 1; i-- >= 0;} { ... i ... }
for (i = N; --i > 0;} { ... i - 1 ... }
for (i = N; --i > 0;} { ... i ... }
for (i = N; --i >= 0;} { ... i - 1 ... }
for (i = N; --i >= 0;} { ... i ... }
for (i = N; i --> 0;) { ... i - 1 ... }
for (i = N; i --> 0;) { ... i ... }
for (i = N; i > 0; i--} { ... i - 1 ... }
for (i = N; i > 0; i--} { ... i ... }
for (i = N; i >= 0; i--} { ... i - 1 ... }
for (i = N; i >= 0; i--} { ... i ... }
for (i = N; i-- > 0;} { ... i - 1 ... }
for (i = N; i-- > 0;} { ... i ... }
for (i = N; i-- >= 0;} { ... i - 1 ... }
for (i = N; i-- >= 0;} { ... i ... }
Home |
Main Index |
Thread Index |
Old Index