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: Tue, 7 Jul 2026 21:11:56 +0200
> From: Roland Illig <roland.illig%gmx.de@localhost>
>
> Am 07.07.2026 16:08:00 schrieb Taylor R Campbell :
>
> > This is the best operator in C! --> is the `goes down to' operator.
>
> How does it come that this "best operator" is neither mentioned in
> operator(7) nor share/misc/style, and that indent(1) formats it as
> two separate operators? All this looks like you're making things up.
I am, of course, being facetious about --> being an operator in and of
itself: it is a post-decrement operator followed by greater-than.
But, even though it is a little cute, after many years of writing
logic that iterates in reverse over half-open intervals, I came to the
entirely serious conclusion that
for (i = N; i --> 0;) { ... i ... }
is much more readable and obvious and safe than any of the
alternatives
for (i = N; i > 0; i--} { ... i - 1 ... }
for (i = N - 1; i >= 0; i--} { ... i ... }
for (i = N; i-- > 0;} { ... i ... }
for (i = N; --i >= 0;} { ... i ... }
as soon as you have spent a moment _once_ to figure out what --> is;
the others all require at least several minutes of thought every time
I look at them to make sure they're doing the right thing, if not
several hours of banging my head against them debugging.
> If you decide that this style is superior, you should adjust the
> aforementioned places (there may be more) and apply this style
> change throughout the whole source tree, for consistency.
I would be happy to do that! But I realize that, on first reaction,
many people find it a little too cute. And we don't have every point
of style variation deterministically spelled out in KNF or enforced in
the tree. For example, we have both `if (!foo)' and `if (! foo)'
throughout the tree already. And we have three different automated
indentation mechanisms (indent(1), NetBSD.el, and clang-format) that
generally agree on what KNF says but disagree on some things it
doesn't say.
Home |
Main Index |
Thread Index |
Old Index