Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > muc.lists.netbsd.source-changes > #156202 > unrolled thread

Re: The --> "operator"

Started byGreg Troxel <gdt@lexort.com>
First post2026-07-08 06:56 -0400
Last post2026-07-09 20:58 -0500
Articles 4 — 3 participants

Back to article view | Back to muc.lists.netbsd.source-changes

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: The --> "operator" Greg Troxel <gdt@lexort.com> - 2026-07-08 06:56 -0400
    Re: The --> "operator" Martin Husemann <martin@duskware.de> - 2026-07-08 13:38 +0200
      Re: The --> "operator" Greg Troxel <gdt@lexort.com> - 2026-07-08 07:44 -0400
        Re: The --> "operator" "Jonathan A. Kollasch" <jakllsch@kollasch.net> - 2026-07-09 20:58 -0500

#156202 — Re: The --> "operator"

FromGreg Troxel <gdt@lexort.com>
Date2026-07-08 06:56 -0400
SubjectRe: The --> "operator"
Message-ID<rmizf0121j2.fsf@s1.lexort.com>
Roland Illig <roland.illig@gmx.de> writes:

> Am 07.07.2026 16:08:00 schrieb Taylor R Campbell :
>
>>> Date: Mon, 6 Jul 2026 00:14:59 +0900
>>> From: Takashi YAMAMOTO <yamt9999@gmail.com>
>>>
>>> @@ -900,7 +897,7 @@ uvm_swap_stats(char *ptr, int misc,
>>>         error = 0;
>>>         count = 0;
>>>         sp = sdps;
>>> -       while (misc-- > 0) {
>>> +       while (misc --> 0) {
>>>
>>> this style change is quite surprising to me. it it intentional?
>>
>> 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.
>
> 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 have never seen --> in C, from reading K&R in 1977 to now.  It looks
like something made up by C++ :-) But seriously, I find it unhelpful.
The semantics of --i and i-- are clear and have been stable for years,
as are the semantics of > and >=.

I would like to see our style guide say explicitly that --> is not
allowed.

--
Posted automagically by a mail2news gateway at muc.de e.V.
Please direct questions, flames, donations, etc. to news-admin@muc.de

[toc] | [next] | [standalone]


#156204

FromMartin Husemann <martin@duskware.de>
Date2026-07-08 13:38 +0200
Message-ID<ak42n8pOg9_S7toI@big-apple.aprisoft.de>
In reply to#156202
On Wed, Jul 08, 2026 at 06:56:01AM -0400, Greg Troxel wrote:
> I have never seen --> in C, from reading K&R in 1977 to now.  It looks
> like something made up by C++ :-) But seriously, I find it unhelpful.
> The semantics of --i and i-- are clear and have been stable for years,
> as are the semantics of > and >=.

There is nothing special about it, and it doesn't matter if you
write it as -- > or --> and give the latter a cute name.

It is two operators, post-decrement and greater-than and it has been
there from the beginning.

Martin

--
Posted automagically by a mail2news gateway at muc.de e.V.
Please direct questions, flames, donations, etc. to news-admin@muc.de

[toc] | [prev] | [next] | [standalone]


#156205

FromGreg Troxel <gdt@lexort.com>
Date2026-07-08 07:44 -0400
Message-ID<rmijyr51z9x.fsf@s1.lexort.com>
In reply to#156204
Martin Husemann <martin@duskware.de> writes:

> On Wed, Jul 08, 2026 at 06:56:01AM -0400, Greg Troxel wrote:
>> I have never seen --> in C, from reading K&R in 1977 to now.  It looks
>> like something made up by C++ :-) But seriously, I find it unhelpful.
>> The semantics of --i and i-- are clear and have been stable for years,
>> as are the semantics of > and >=.
>
> There is nothing special about it, and it doesn't matter if you
> write it as -- > or --> and give the latter a cute name.
>
> It is two operators, post-decrement and greater-than and it has been
> there from the beginning.

I meant that writing it as "-->" is irregular, and I find it unhelpful.

I also find i-- in a for loop update step (middle) to be unhelpful for
clarity, as the test is done on a different value that the loop sees.

This feels like "it's twice as hard to debug code than to write it, so
only write code that is half as clever as you are capable of".  I found
that "writing for the code reviewer" led to code that was as simple and
clear as it could be, and this helped reliability, back when I was
in an environment with review.

--
Posted automagically by a mail2news gateway at muc.de e.V.
Please direct questions, flames, donations, etc. to news-admin@muc.de

[toc] | [prev] | [next] | [standalone]


#156213

From"Jonathan A. Kollasch" <jakllsch@kollasch.net>
Date2026-07-09 20:58 -0500
Message-ID<alBRzz/fqBqpdybN@tazenda.kollasch.net>
In reply to#156205
On Wed, Jul 08, 2026 at 07:44:42AM -0400, Greg Troxel wrote:
> Martin Husemann <martin@duskware.de> writes:
> 
> > On Wed, Jul 08, 2026 at 06:56:01AM -0400, Greg Troxel wrote:
> >> I have never seen --> in C, from reading K&R in 1977 to now.  It looks
> >> like something made up by C++ :-) But seriously, I find it unhelpful.
> >> The semantics of --i and i-- are clear and have been stable for years,
> >> as are the semantics of > and >=.
> >
> > There is nothing special about it, and it doesn't matter if you
> > write it as -- > or --> and give the latter a cute name.
> >
> > It is two operators, post-decrement and greater-than and it has been
> > there from the beginning.
> 
> I meant that writing it as "-->" is irregular, and I find it unhelpful.
> 
> I also find i-- in a for loop update step (middle) to be unhelpful for
> clarity, as the test is done on a different value that the loop sees.
> 
> This feels like "it's twice as hard to debug code than to write it, so
> only write code that is half as clever as you are capable of".  I found
> that "writing for the code reviewer" led to code that was as simple and
> clear as it could be, and this helped reliability, back when I was
> in an environment with review.

As someone who has actually tried to write, from scratch, reverse
iteration from ${UNSIGNEDTYPE}_MAX down to and including zero loops in C
correctly, using the same unsigned type as the index, I have to say that
it is not as obvious as you might think.

I kept trying to make it look like forward iteration with the index
adjustment in the third for() position, but there is no way to make it
work correctly in all implementations that way.

I tried to do index adjustment within the loop body itself.  I quickly
realized that I did not want to rely on the implementation-defined
underflow/overflow behavior you need to be defined when you alter the
index into another index variable within the loop body.

With Taylor's suggestion of post-decrement in the condition position, I
got it working.

I can't say I have a strong preference for 'i --> 0' over 'i-- > 0', but
having it be contrary to typical 'style' certainly makes the atypical
idiom stand out.  It probably needs to stand out; but it doesn't need to
stand out as much as a whole block comment before such a loop.

	Jonathan Kollasch

--
Posted automagically by a mail2news gateway at muc.de e.V.
Please direct questions, flames, donations, etc. to news-admin@muc.de

[toc] | [prev] | [standalone]


Back to top | Article view | muc.lists.netbsd.source-changes


csiph-web