Rocksolid Light

Welcome to novaBBS (click a section below)

mail  files  register  newsreader  groups  login

Message-ID:  

The reason computer chips are so small is computers don't eat much.


devel / comp.lang.c / Re: qsort() vs. std::sort

SubjectAuthor
* qsort() vs. std::sortBonita Montero
+- Re: qsort() vs. std::sortBonita Montero
+* Re: qsort() vs. std::sortfir
|+- Re: qsort() vs. std::sortfir
|`* Re: qsort() vs. std::sortBonita Montero
| +* Re: qsort() vs. std::sortfir
| |`* Re: qsort() vs. std::sortBonita Montero
| | `* Re: qsort() vs. std::sortfir
| |  `* Re: qsort() vs. std::sortBonita Montero
| |   `- Re: qsort() vs. std::sortfir
| `* Re: qsort() vs. std::sortDolores Filandro
|  +* Re: qsort() vs. std::sortAndrey Tarasevich
|  |`* The missing sgn() function (Was: qsort() vs. std::sort)Kenny McCormack
|  | `* Re: The missing sgn() function (Was: qsort() vs. std::sort)Andrey Tarasevich
|  |  `* Re: The missing sgn() function (Was: qsort() vs. std::sort)Andrey Tarasevich
|  |   `* Re: The missing sgn() function (Was: qsort() vs. std::sort)Dolores Filandro
|  |    `* Re: The missing sgn() function (Was: qsort() vs. std::sort)Malcolm McLean
|  |     `- Re: The missing sgn() functionKeith Thompson
|  +* Re: qsort() vs. std::sortStefan Ram
|  |`- Re: qsort() vs. std::sortStefan Ram
|  `* Re: qsort() vs. std::sortBonita Montero
|   +* Re: qsort() vs. std::sortScott Lurndal
|   |`- Re: qsort() vs. std::sortBonita Montero
|   `* Re: qsort() vs. std::sortAndrey Tarasevich
|    `* Re: qsort() vs. std::sortBonita Montero
|     +* Re: qsort() vs. std::sortÖö Tiib
|     |`* Re: qsort() vs. std::sortBonita Montero
|     | `* Re: qsort() vs. std::sortjames...@alumni.caltech.edu
|     |  `* Re: qsort() vs. std::sortBonita Montero
|     |   `* Re: qsort() vs. std::sortjames...@alumni.caltech.edu
|     |    `- Re: qsort() vs. std::sortBonita Montero
|     `- Re: qsort() vs. std::sortjames...@alumni.caltech.edu
+* Re: qsort() vs. std::sortMalcolm McLean
|+- Re: qsort() vs. std::sortfir
|`- Re: qsort() vs. std::sortBonita Montero
+* Re: qsort() vs. std::sortJuha Nieminen
|+- Re: qsort() vs. std::sortBonita Montero
|`- Re: qsort() vs. std::sortMalcolm McLean
+* Re: qsort() vs. std::sortThiago Adams
|`* Re: qsort() vs. std::sortBonita Montero
| `* Re: qsort() vs. std::sortWilliam Ahern
|  `* Re: qsort() vs. std::sortBonita Montero
|   +* Re: qsort() vs. std::sortWilliam Ahern
|   |`- Re: qsort() vs. std::sortMalcolm McLean
|   `- Re: qsort() vs. std::sortThiago Adams
`* Re: qsort() vs. std::sortWilliam Ahern
 +- Re: qsort() vs. std::sortBonita Montero
 `* Re: qsort() vs. std::sortJuha Nieminen
  `- Re: qsort() vs. std::sortWilliam Ahern

Pages:12
Re: qsort() vs. std::sort

<1b291f6d-19de-473c-ab66-9d20d11c3930n@googlegroups.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=21532&group=comp.lang.c#21532

  copy link   Newsgroups: comp.lang.c
X-Received: by 2002:a0c:b3cf:0:b0:456:4e1b:8da4 with SMTP id b15-20020a0cb3cf000000b004564e1b8da4mr6862218qvf.86.1651142844765;
Thu, 28 Apr 2022 03:47:24 -0700 (PDT)
X-Received: by 2002:a05:6214:4108:b0:456:31ce:d5ff with SMTP id
kc8-20020a056214410800b0045631ced5ffmr16372021qvb.127.1651142844637; Thu, 28
Apr 2022 03:47:24 -0700 (PDT)
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!news.misty.com!border2.nntp.dca1.giganews.com!nntp.giganews.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.c
Date: Thu, 28 Apr 2022 03:47:24 -0700 (PDT)
In-Reply-To: <lk6qji-no21.ln1@wilbur.25thandClement.com>
Injection-Info: google-groups.googlegroups.com; posting-host=2a00:23a8:400a:5601:a0d7:a28a:22c5:f653;
posting-account=Dz2zqgkAAADlK5MFu78bw3ab-BRFV4Qn
NNTP-Posting-Host: 2a00:23a8:400a:5601:a0d7:a28a:22c5:f653
References: <t4092b$des$1@dont-email.me> <20115f32-0400-4813-8ddb-5be877eba3d6n@googlegroups.com>
<t4bre0$6ni$2@dont-email.me> <kk2pji-tuv1.ln1@wilbur.25thandClement.com>
<t4d6ut$om6$1@dont-email.me> <lk6qji-no21.ln1@wilbur.25thandClement.com>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <1b291f6d-19de-473c-ab66-9d20d11c3930n@googlegroups.com>
Subject: Re: qsort() vs. std::sort
From: malcolm....@gmail.com (Malcolm McLean)
Injection-Date: Thu, 28 Apr 2022 10:47:24 +0000
Content-Type: text/plain; charset="UTF-8"
Lines: 49
 by: Malcolm McLean - Thu, 28 Apr 2022 10:47 UTC

On Thursday, 28 April 2022 at 11:30:20 UTC+1, William Ahern wrote:
> Bonita Montero <Bonita....@gmail.com> wrote:
> > Am 28.04.2022 um 02:10 schrieb William Ahern:
> >> Bonita Montero <Bonita....@gmail.com> wrote:
> >>> Am 27.04.2022 um 13:21 schrieb Thiago Adams:
> >> <snip>
> >>>> If a C programmer has concerns about qsort performance he just
> >>>> make it inline removing the function comparison pointer and using
> >>>> the function directly.
> >>>
> >>> 1. You can't inline a function with arbitrary recursion.
> >>
> >> The same is true in C++.
> >>
> >>> 2. The comparison-function for qsort() is never inlined.
> >>
> >> That's a toolchain issue. Nothing prevents C environments from inlining
> >> qsort and it's callback; ...
> >
> > The qsort-function is a static piece of code and the comparison
> > -function is never inlined.
> See disassembly posted elsethread. I've given all the information needed to
> quickly reproduce this for yourself, assuming some minimal familiarity with
> GCC.
>
> Alpine Linux isn't even needed, it's just what I started with out of
> caution. I just now reproduced the distinctive benchmark profiles between
> qsort-inline and qsort-extern on macOS 12.3.1 after removing -Wl,-rpath from
> CFLAGS. (The macOS/mach-O linker doesn't recognize the -rpath option, but
> it's linker embeds and uses the original location by default, anyhow.) I
> don't know off-hand how to get a proper disassembly on macOS (-flto
> complicates things considerably), but there's no reason to believe that the
> comparator wasn't inlined like it was on Linux.
>
> As another poster mentioned, templates are good for much more than
> performance inlining. But I've always had a gripe with the qsort vs
> std::qsort meme in particular: it confuses C toolchains and historical
> linking semantics with the language itself. It should be clear, now, that C
> language semantics don't prevent inlining of a comparator passed to a
> sorting function; now even one defined externally to the invoking source
> unit. (Unless somehow I've missed that a standard routine can't be inlined
> without violating the standard--e.g. that the symbol has to have a unique
> address.)
>
That an interesting one. The comparison function can have side-effects,
so it could do something with its own address, like printing it out. Does
that address have to match the address of the fucntion when taken globally?
I think it does.
That would make inlining a lot more complicated, just to catch one almost
useless exceptional case.

Re: qsort() vs. std::sort

<94c70098-b932-4383-bfb2-2234786d9d89n@googlegroups.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=21536&group=comp.lang.c#21536

  copy link   Newsgroups: comp.lang.c
X-Received: by 2002:a37:c44:0:b0:69f:81cb:1d6a with SMTP id 65-20020a370c44000000b0069f81cb1d6amr7034663qkm.494.1651145412052;
Thu, 28 Apr 2022 04:30:12 -0700 (PDT)
X-Received: by 2002:a05:620a:2544:b0:680:a53b:ec1a with SMTP id
s4-20020a05620a254400b00680a53bec1amr19448915qko.544.1651145411874; Thu, 28
Apr 2022 04:30:11 -0700 (PDT)
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!news.misty.com!border2.nntp.dca1.giganews.com!nntp.giganews.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.c
Date: Thu, 28 Apr 2022 04:30:11 -0700 (PDT)
In-Reply-To: <t4d6ut$om6$1@dont-email.me>
Injection-Info: google-groups.googlegroups.com; posting-host=179.152.28.66; posting-account=xFcAQAoAAAAoWlfpQ6Hz2n-MU9fthxbY
NNTP-Posting-Host: 179.152.28.66
References: <t4092b$des$1@dont-email.me> <20115f32-0400-4813-8ddb-5be877eba3d6n@googlegroups.com>
<t4bre0$6ni$2@dont-email.me> <kk2pji-tuv1.ln1@wilbur.25thandClement.com> <t4d6ut$om6$1@dont-email.me>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <94c70098-b932-4383-bfb2-2234786d9d89n@googlegroups.com>
Subject: Re: qsort() vs. std::sort
From: thiago.a...@gmail.com (Thiago Adams)
Injection-Date: Thu, 28 Apr 2022 11:30:12 +0000
Content-Type: text/plain; charset="UTF-8"
Lines: 27
 by: Thiago Adams - Thu, 28 Apr 2022 11:30 UTC

On Thursday, April 28, 2022 at 1:59:23 AM UTC-3, Bonita Montero wrote:
> Am 28.04.2022 um 02:10 schrieb William Ahern:
> > Bonita Montero <Bonita....@gmail.com> wrote:
> >> Am 27.04.2022 um 13:21 schrieb Thiago Adams:
> > <snip>
> >>> If a C programmer has concerns about qsort performance he just
> >>> make it inline removing the function comparison pointer and using
> >>> the function directly.
> >>
> >> 1. You can't inline a function with arbitrary recursion.
> >
> > The same is true in C++.
> >
> >> 2. The comparison-function for qsort() is never inlined.
> >
> > That's a toolchain issue. Nothing prevents C environments from inlining
> > qsort and it's callback; ...
>
> The qsort-function is a static piece of code and the comparison
> -function is never inlined.

What I mean by " removing the function comparison pointer and using
the function directly." is to create a copy of the code replacing the
function pointer. Like instantiating the template function manually.
The idea C++ is faster than C is always very superficial. C is not
a language to expect a big framework to compare against something else
(samples like qsort x std::sort are rare), instead C is a language what you
do whatever you want given you fine control about performance.

Re: qsort() vs. std::sort

<72998849-f697-43e0-ad24-2cef111c8f36n@googlegroups.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=21620&group=comp.lang.c#21620

  copy link   Newsgroups: comp.lang.c
X-Received: by 2002:a05:6214:1d29:b0:45b:cf:f242 with SMTP id f9-20020a0562141d2900b0045b00cff242mr2553498qvd.82.1651985147416;
Sat, 07 May 2022 21:45:47 -0700 (PDT)
X-Received: by 2002:ad4:5bc7:0:b0:45b:ab2:6d04 with SMTP id
t7-20020ad45bc7000000b0045b0ab26d04mr215862qvt.75.1651985147255; Sat, 07 May
2022 21:45:47 -0700 (PDT)
Path: i2pn2.org!i2pn.org!news.uzoreto.com!news-out.netnews.com!news.alt.net!fdc2.netnews.com!peer02.ams1!peer.ams1.xlned.com!news.xlned.com!peer03.iad!feed-me.highwinds-media.com!news.highwinds-media.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.c
Date: Sat, 7 May 2022 21:45:47 -0700 (PDT)
In-Reply-To: <t40rkb$k2k$1@dont-email.me>
Injection-Info: google-groups.googlegroups.com; posting-host=71.125.250.166; posting-account=BtBOEwoAAAAFZDKynGutKL1bxHMXo3Ay
NNTP-Posting-Host: 71.125.250.166
References: <t4092b$des$1@dont-email.me> <bb6cb651-6c86-49cc-bdee-83623c2bfb83n@googlegroups.com>
<t40rkb$k2k$1@dont-email.me>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <72998849-f697-43e0-ad24-2cef111c8f36n@googlegroups.com>
Subject: Re: qsort() vs. std::sort
From: dolfila...@gmail.com (Dolores Filandro)
Injection-Date: Sun, 08 May 2022 04:45:47 +0000
Content-Type: text/plain; charset="UTF-8"
X-Received-Bytes: 1421
 by: Dolores Filandro - Sun, 8 May 2022 04:45 UTC

> {
> unsigned
> &l = *(unsigned *)left,
> &r = *(unsigned *)right;
> return l < r ? -1 : l > r ? 1 : 0;
> } );

(l > r ? 1 : 0) means exactly the same thing as (l > r)

Re: qsort() vs. std::sort

<t580j5$hlc$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=21621&group=comp.lang.c#21621

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: andreyta...@hotmail.com (Andrey Tarasevich)
Newsgroups: comp.lang.c
Subject: Re: qsort() vs. std::sort
Date: Sun, 8 May 2022 01:56:01 -0700
Organization: A noiseless patient Spider
Lines: 19
Message-ID: <t580j5$hlc$1@dont-email.me>
References: <t4092b$des$1@dont-email.me>
<bb6cb651-6c86-49cc-bdee-83623c2bfb83n@googlegroups.com>
<t40rkb$k2k$1@dont-email.me>
<72998849-f697-43e0-ad24-2cef111c8f36n@googlegroups.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Sun, 8 May 2022 08:56:05 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="222834d98921b2fe54180c6335adc338";
logging-data="18092"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18A2w9QhSgLsKK+8yf7zcv9"
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101
Thunderbird/91.9.0
Cancel-Lock: sha1:jcO537YNhplGShxtHc0rPl044ho=
In-Reply-To: <72998849-f697-43e0-ad24-2cef111c8f36n@googlegroups.com>
Content-Language: en-US
 by: Andrey Tarasevich - Sun, 8 May 2022 08:56 UTC

On 5/7/2022 9:45 PM, Dolores Filandro wrote:
>
>> {
>> unsigned
>> &l = *(unsigned *)left,
>> &r = *(unsigned *)right;
>> return l < r ? -1 : l > r ? 1 : 0;
>> } );
>
>
> (l > r ? 1 : 0) means exactly the same thing as (l > r)

.... which is why one usually expresses the above as the idiomatic

return (l > r) - (l < r);

--
Best regards,
Andrey

The missing sgn() function (Was: qsort() vs. std::sort)

<t58m9r$3urcd$1@news.xmission.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=21623&group=comp.lang.c#21623

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!xmission!nnrp.xmission!.POSTED.shell.xmission.com!not-for-mail
From: gaze...@shell.xmission.com (Kenny McCormack)
Newsgroups: comp.lang.c
Subject: The missing sgn() function (Was: qsort() vs. std::sort)
Date: Sun, 8 May 2022 15:06:35 -0000 (UTC)
Organization: The official candy of the new Millennium
Message-ID: <t58m9r$3urcd$1@news.xmission.com>
References: <t4092b$des$1@dont-email.me> <t40rkb$k2k$1@dont-email.me> <72998849-f697-43e0-ad24-2cef111c8f36n@googlegroups.com> <t580j5$hlc$1@dont-email.me>
Injection-Date: Sun, 8 May 2022 15:06:35 -0000 (UTC)
Injection-Info: news.xmission.com; posting-host="shell.xmission.com:166.70.8.4";
logging-data="4156813"; mail-complaints-to="abuse@xmission.com"
X-Newsreader: trn 4.0-test77 (Sep 1, 2010)
Originator: gazelle@shell.xmission.com (Kenny McCormack)
 by: Kenny McCormack - Sun, 8 May 2022 15:06 UTC

In article <t580j5$hlc$1@dont-email.me>,
Andrey Tarasevich <andreytarasevich@hotmail.com> wrote:
>On 5/7/2022 9:45 PM, Dolores Filandro wrote:
>>
>>> {
>>> unsigned
>>> &l = *(unsigned *)left,
>>> &r = *(unsigned *)right;
>>> return l < r ? -1 : l > r ? 1 : 0;
>>> } );
>>
>>
>> (l > r ? 1 : 0) means exactly the same thing as (l > r)
>
>... which is why one usually expresses the above as the idiomatic
>
> return (l > r) - (l < r);

Which is why I've always thought it was dumb that the standard library
(both in C and in some "C-like" languages) doesn't provide the sgn()
function. It means that everybody has to re-invent the above idiom.

Incidentally, is any of this necessary? I have not been following this
discussion, so I may have missed something, but if we are talking about the
qsort() function, then it is not necessary to return exactly one of -1, 0,
or 1. Any negative number will do, as will any positive one. So, all you
need is (l-r).

--
The single most important statistic in the US today - the one that explains all the
others - is this: 63 million people thought it was a good idea to vote for this clown
(and will probably do so again). Everything else is secondary to that. Everything else
could be fixed if we can revert this one statistic. Nothing can be fixed until we do.

Re: qsort() vs. std::sort

<code-20220508173435@ram.dialup.fu-berlin.de>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=21624&group=comp.lang.c#21624

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!not-for-mail
From: ram...@zedat.fu-berlin.de (Stefan Ram)
Newsgroups: comp.lang.c
Subject: Re: qsort() vs. std::sort
Date: 8 May 2022 16:35:32 GMT
Organization: Stefan Ram
Lines: 26
Expires: 1 Apr 2023 11:59:58 GMT
Message-ID: <code-20220508173435@ram.dialup.fu-berlin.de>
References: <t4092b$des$1@dont-email.me> <bb6cb651-6c86-49cc-bdee-83623c2bfb83n@googlegroups.com> <t40rkb$k2k$1@dont-email.me> <72998849-f697-43e0-ad24-2cef111c8f36n@googlegroups.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
X-Trace: news.uni-berlin.de R+4/gk3fza0jQJG9arMJBwXhQJ73Ewcydmg6lIW7xLCPBY
X-Copyright: (C) Copyright 2022 Stefan Ram. All rights reserved.
Distribution through any means other than regular usenet
channels is forbidden. It is forbidden to publish this
article in the Web, to change URIs of this article into links,
and to transfer the body without this notice, but quotations
of parts in other Usenet posts are allowed.
X-No-Archive: Yes
Archive: no
X-No-Archive-Readme: "X-No-Archive" is set, because this prevents some
services to mirror the article in the web. But the article may
be kept on a Usenet archive server with only NNTP access.
X-No-Html: yes
Content-Language: en-US
Accept-Language: de-DE, en-US, it, fr-FR
 by: Stefan Ram - Sun, 8 May 2022 16:35 UTC

Dolores Filandro <dolfiland8@gmail.com> writes:
>> {
>> unsigned
>> &l = *(unsigned *)left,
>> &r = *(unsigned *)right;
>> return l < r ? -1 : l > r ? 1 : 0;
>> } );
>(l > r ? 1 : 0) means exactly the same thing as (l > r)

A programmer might implement a specification that says,

-1 if l < r
result = { 1 if l > r
0 , otherwise.

. Then, - somewhat redundant - code such as

return
l < r? -1:
l > r? 1:
0;

might make it easier to verify during code inspections that
the code implements the specification.

Re: The missing sgn() function (Was: qsort() vs. std::sort)

<t58tdg$8q5$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=21626&group=comp.lang.c#21626

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: andreyta...@hotmail.com (Andrey Tarasevich)
Newsgroups: comp.lang.c
Subject: Re: The missing sgn() function (Was: qsort() vs. std::sort)
Date: Sun, 8 May 2022 10:07:56 -0700
Organization: A noiseless patient Spider
Lines: 46
Message-ID: <t58tdg$8q5$1@dont-email.me>
References: <t4092b$des$1@dont-email.me> <t40rkb$k2k$1@dont-email.me>
<72998849-f697-43e0-ad24-2cef111c8f36n@googlegroups.com>
<t580j5$hlc$1@dont-email.me> <t58m9r$3urcd$1@news.xmission.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Sun, 8 May 2022 17:08:00 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="222834d98921b2fe54180c6335adc338";
logging-data="9029"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19LmfKZDtDKtpAFvoFZct3e"
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101
Thunderbird/91.9.0
Cancel-Lock: sha1:9OO2b5kV02+AHK3vjL/1SEgtDDg=
In-Reply-To: <t58m9r$3urcd$1@news.xmission.com>
Content-Language: en-US
 by: Andrey Tarasevich - Sun, 8 May 2022 17:07 UTC

On 5/8/2022 8:06 AM, Kenny McCormack wrote:
> In article <t580j5$hlc$1@dont-email.me>,
> Andrey Tarasevich <andreytarasevich@hotmail.com> wrote:
>> On 5/7/2022 9:45 PM, Dolores Filandro wrote:
>>>
>>>> {
>>>> unsigned
>>>> &l = *(unsigned *)left,
>>>> &r = *(unsigned *)right;
>>>> return l < r ? -1 : l > r ? 1 : 0;
>>>> } );
>>>
>>>
>>> (l > r ? 1 : 0) means exactly the same thing as (l > r)
>>
>> ... which is why one usually expresses the above as the idiomatic
>>
>> return (l > r) - (l < r);
>
> Which is why I've always thought it was dumb that the standard library
> (both in C and in some "C-like" languages) doesn't provide the sgn()
> function. It means that everybody has to re-invent the above idiom.
>
> Incidentally, is any of this necessary? I have not been following this
> discussion, so I may have missed something, but if we are talking about the
> qsort() function, then it is not necessary to return exactly one of -1, 0,
> or 1. Any negative number will do, as will any positive one. So, all you
> need is (l-r).

No. `l - r` is a major anti-pattern and is often a bug.

Firstly, this will not work at all for unsigned types as in the original
example. Secondly, in general this will not work for signed types since
it can/will overflow.

The only case when you can get away with `l - r` is smaller-than-int
types (which are promoted to `int` and can't overflow), and situations
where "you are absolutely sure" the values are so small that overflow
can't happen.

But it is not really worth it, when one has `(l > r) - (l < r)`.

--
Best regards,
Andrey

Re: qsort() vs. std::sort

<sign-20220508180830@ram.dialup.fu-berlin.de>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=21627&group=comp.lang.c#21627

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!not-for-mail
From: ram...@zedat.fu-berlin.de (Stefan Ram)
Newsgroups: comp.lang.c
Subject: Re: qsort() vs. std::sort
Date: 8 May 2022 17:10:55 GMT
Organization: Stefan Ram
Lines: 33
Expires: 1 Apr 2023 11:59:58 GMT
Message-ID: <sign-20220508180830@ram.dialup.fu-berlin.de>
References: <t4092b$des$1@dont-email.me> <bb6cb651-6c86-49cc-bdee-83623c2bfb83n@googlegroups.com> <t40rkb$k2k$1@dont-email.me> <72998849-f697-43e0-ad24-2cef111c8f36n@googlegroups.com> <code-20220508173435@ram.dialup.fu-berlin.de>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
X-Trace: news.uni-berlin.de xJIte01piIF5MHONXQUPGgWorpfYe62WRiCRgqKglLd77L
X-Copyright: (C) Copyright 2022 Stefan Ram. All rights reserved.
Distribution through any means other than regular usenet
channels is forbidden. It is forbidden to publish this
article in the Web, to change URIs of this article into links,
and to transfer the body without this notice, but quotations
of parts in other Usenet posts are allowed.
X-No-Archive: Yes
Archive: no
X-No-Archive-Readme: "X-No-Archive" is set, because this prevents some
services to mirror the article in the web. But the article may
be kept on a Usenet archive server with only NNTP access.
X-No-Html: yes
Content-Language: en-US
Accept-Language: de-DE, en-US, it, fr-FR
 by: Stefan Ram - Sun, 8 May 2022 17:10 UTC

ram@zedat.fu-berlin.de (Stefan Ram) writes:
>. Then, - somewhat redundant - code such as
>return
>l < r? -1:
>l > r? 1:
> 0;
>might make it easier to verify during code inspections that
>the code implements the specification.

I did a search for it, and found only few definitions:

|#define sign(z) ((z) < 0 ? -1 : ((z) > 0 ? 1 : 0))
nethack

. Sometimes, first, a two-argument sign is defined,
sign(a,b), as the value of a with the sign of b. The
one-argument sign then sometimes is defined as sign(1,b).

Sometimes, just two values are wanted.

|double
|sgn (double __x)
|{
| return __x >= 0.0 ? 1.0 : -1.0;
|}
gcc testsuite

Sometimes, non-portable code is accepted.

|#define SIGN(fp) ((fp) & SIGNBIT)
libgcc

Re: The missing sgn() function (Was: qsort() vs. std::sort)

<t58toa$ase$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=21628&group=comp.lang.c#21628

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: andreyta...@hotmail.com (Andrey Tarasevich)
Newsgroups: comp.lang.c
Subject: Re: The missing sgn() function (Was: qsort() vs. std::sort)
Date: Sun, 8 May 2022 10:13:45 -0700
Organization: A noiseless patient Spider
Lines: 56
Message-ID: <t58toa$ase$1@dont-email.me>
References: <t4092b$des$1@dont-email.me> <t40rkb$k2k$1@dont-email.me>
<72998849-f697-43e0-ad24-2cef111c8f36n@googlegroups.com>
<t580j5$hlc$1@dont-email.me> <t58m9r$3urcd$1@news.xmission.com>
<t58tdg$8q5$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Sun, 8 May 2022 17:13:47 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="222834d98921b2fe54180c6335adc338";
logging-data="11150"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/L6diXvCX/pnm987GbICo4"
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101
Thunderbird/91.9.0
Cancel-Lock: sha1:ErbNqOLAsV5rmGVYHn8QFROq2bw=
In-Reply-To: <t58tdg$8q5$1@dont-email.me>
Content-Language: en-US
 by: Andrey Tarasevich - Sun, 8 May 2022 17:13 UTC

On 5/8/2022 10:07 AM, Andrey Tarasevich wrote:
> On 5/8/2022 8:06 AM, Kenny McCormack wrote:
>> In article <t580j5$hlc$1@dont-email.me>,
>> Andrey Tarasevich  <andreytarasevich@hotmail.com> wrote:
>>> On 5/7/2022 9:45 PM, Dolores Filandro wrote:
>>>>
>>>>> {
>>>>> unsigned
>>>>> &l = *(unsigned *)left,
>>>>> &r = *(unsigned *)right;
>>>>> return l < r ? -1 : l > r ? 1 : 0;
>>>>> } );
>>>>
>>>>
>>>> (l > r ? 1 : 0)  means exactly the same thing as  (l > r)
>>>
>>> ... which is why one usually expresses the above as the idiomatic
>>>
>>>    return (l > r) - (l < r);
>>
>> Which is why I've always thought it was dumb that the standard library
>> (both in C and in some "C-like" languages) doesn't provide the sgn()
>> function.  It means that everybody has to re-invent the above idiom.
>>
>> Incidentally, is any of this necessary?  I have not been following this
>> discussion, so I may have missed something, but if we are talking
>> about the
>> qsort() function, then it is not necessary to return exactly one of
>> -1, 0,
>> or 1.  Any negative number will do, as will any positive one.  So, all
>> you
>> need is (l-r).
>
> No. `l - r` is a major anti-pattern and is often a bug.
>
> Firstly, this will not work at all for unsigned types as in the original
> example. Secondly, in general this will not work for signed types since
> it can/will overflow.
>
> The only case when you can get away with `l - r` is smaller-than-int
> types (which are promoted to `int` and can't overflow), and situations
> where "you are absolutely sure" the values are so small that overflow
> can't happen.
>
> But it is not really worth it, when one has `(l > r) - (l < r)`.

Of course, one can always argue that `(l > r) - (l < r)` is also a
variation of `l - r` where the values are pre-normalized to ensure they
"are so small that overflow can't happen".

:O)

--
Best regards,
Andrey

Re: The missing sgn() function (Was: qsort() vs. std::sort)

<05da37f2-818a-4ff5-a343-d7f500f37461n@googlegroups.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=21629&group=comp.lang.c#21629

  copy link   Newsgroups: comp.lang.c
X-Received: by 2002:ac8:7f43:0:b0:2f3:d55d:7296 with SMTP id g3-20020ac87f43000000b002f3d55d7296mr7374586qtk.635.1652115644212;
Mon, 09 May 2022 10:00:44 -0700 (PDT)
X-Received: by 2002:a05:6214:13e5:b0:458:812:217e with SMTP id
ch5-20020a05621413e500b004580812217emr14223856qvb.60.1652115644004; Mon, 09
May 2022 10:00:44 -0700 (PDT)
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!proxad.net!feeder1-2.proxad.net!209.85.160.216.MISMATCH!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.c
Date: Mon, 9 May 2022 10:00:43 -0700 (PDT)
In-Reply-To: <t58toa$ase$1@dont-email.me>
Injection-Info: google-groups.googlegroups.com; posting-host=71.125.250.166; posting-account=BtBOEwoAAAAFZDKynGutKL1bxHMXo3Ay
NNTP-Posting-Host: 71.125.250.166
References: <t4092b$des$1@dont-email.me> <t40rkb$k2k$1@dont-email.me>
<72998849-f697-43e0-ad24-2cef111c8f36n@googlegroups.com> <t580j5$hlc$1@dont-email.me>
<t58m9r$3urcd$1@news.xmission.com> <t58tdg$8q5$1@dont-email.me> <t58toa$ase$1@dont-email.me>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <05da37f2-818a-4ff5-a343-d7f500f37461n@googlegroups.com>
Subject: Re: The missing sgn() function (Was: qsort() vs. std::sort)
From: dolfila...@gmail.com (Dolores Filandro)
Injection-Date: Mon, 09 May 2022 17:00:44 +0000
Content-Type: text/plain; charset="UTF-8"
 by: Dolores Filandro - Mon, 9 May 2022 17:00 UTC

On Sunday, May 8, 2022 at 1:13:58 PM UTC-4, Andrey Tarasevich wrote:
> On 5/8/2022 10:07 AM, Andrey Tarasevich wrote:
> > On 5/8/2022 8:06 AM, Kenny McCormack wrote:
> >> In article <t580j5$hlc$1...@dont-email.me>,
> >> Andrey Tarasevich <andreyta...@hotmail.com> wrote:
> >>> On 5/7/2022 9:45 PM, Dolores Filandro wrote:
> >>>>
> >>>>> {
> >>>>> unsigned
> >>>>> &l = *(unsigned *)left,
> >>>>> &r = *(unsigned *)right;
> >>>>> return l < r ? -1 : l > r ? 1 : 0;
> >>>>> } );
> >>>>
> >>>>
> >>>> (l > r ? 1 : 0) means exactly the same thing as (l > r)
> >>>
> >>> ... which is why one usually expresses the above as the idiomatic
> >>>
> >>> return (l > r) - (l < r);
> >>
> >> Which is why I've always thought it was dumb that the standard library
> >> (both in C and in some "C-like" languages) doesn't provide the sgn()
> >> function. It means that everybody has to re-invent the above idiom.
> >>
> >> Incidentally, is any of this necessary? I have not been following this
> >> discussion, so I may have missed something, but if we are talking
> >> about the
> >> qsort() function, then it is not necessary to return exactly one of
> >> -1, 0,
> >> or 1. Any negative number will do, as will any positive one. So, all
> >> you
> >> need is (l-r).
> >
> > No. `l - r` is a major anti-pattern and is often a bug.
> >
> > Firstly, this will not work at all for unsigned types as in the original
> > example. Secondly, in general this will not work for signed types since
> > it can/will overflow.
> >
> > The only case when you can get away with `l - r` is smaller-than-int
> > types (which are promoted to `int` and can't overflow), and situations
> > where "you are absolutely sure" the values are so small that overflow
> > can't happen.
> >
> > But it is not really worth it, when one has `(l > r) - (l < r)`.
> Of course, one can always argue that `(l > r) - (l < r)` is also a
> variation of `l - r` where the values are pre-normalized to ensure they
> "are so small that overflow can't happen".
> :O)
>
> --
> Best regards,
> Andrey

But what I was getting at, is that
for OP representing any relational or equality operator, ==, !=, >, <, et cetera,
and with any text substitutions for A and B
the expression ((A) OP (B)) means *Exactly* the same thing as the expression ((A) OP (B) ? 1 : 0)
Same type
Same value
Same side effects
to the extent that a compiler can always render the exact same op code for either expression.

Re: The missing sgn() function (Was: qsort() vs. std::sort)

<cd0af991-5328-4605-bd53-3269a9ce3548n@googlegroups.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=21630&group=comp.lang.c#21630

  copy link   Newsgroups: comp.lang.c
X-Received: by 2002:a05:622a:104d:b0:2f3:bc09:f05 with SMTP id f13-20020a05622a104d00b002f3bc090f05mr16537411qte.396.1652122048793;
Mon, 09 May 2022 11:47:28 -0700 (PDT)
X-Received: by 2002:a37:b605:0:b0:69e:6d6f:aea7 with SMTP id
g5-20020a37b605000000b0069e6d6faea7mr12596478qkf.655.1652122048576; Mon, 09
May 2022 11:47:28 -0700 (PDT)
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!usenet.blueworldhosting.com!feed1.usenet.blueworldhosting.com!peer02.iad!feed-me.highwinds-media.com!news.highwinds-media.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.c
Date: Mon, 9 May 2022 11:47:28 -0700 (PDT)
In-Reply-To: <05da37f2-818a-4ff5-a343-d7f500f37461n@googlegroups.com>
Injection-Info: google-groups.googlegroups.com; posting-host=2a00:23a8:400a:5601:942c:ea35:908c:9324;
posting-account=Dz2zqgkAAADlK5MFu78bw3ab-BRFV4Qn
NNTP-Posting-Host: 2a00:23a8:400a:5601:942c:ea35:908c:9324
References: <t4092b$des$1@dont-email.me> <t40rkb$k2k$1@dont-email.me>
<72998849-f697-43e0-ad24-2cef111c8f36n@googlegroups.com> <t580j5$hlc$1@dont-email.me>
<t58m9r$3urcd$1@news.xmission.com> <t58tdg$8q5$1@dont-email.me>
<t58toa$ase$1@dont-email.me> <05da37f2-818a-4ff5-a343-d7f500f37461n@googlegroups.com>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <cd0af991-5328-4605-bd53-3269a9ce3548n@googlegroups.com>
Subject: Re: The missing sgn() function (Was: qsort() vs. std::sort)
From: malcolm....@gmail.com (Malcolm McLean)
Injection-Date: Mon, 09 May 2022 18:47:28 +0000
Content-Type: text/plain; charset="UTF-8"
X-Received-Bytes: 4468
 by: Malcolm McLean - Mon, 9 May 2022 18:47 UTC

On Monday, 9 May 2022 at 18:00:51 UTC+1, Dolores Filandro wrote:
> On Sunday, May 8, 2022 at 1:13:58 PM UTC-4, Andrey Tarasevich wrote:
> > On 5/8/2022 10:07 AM, Andrey Tarasevich wrote:
> > > On 5/8/2022 8:06 AM, Kenny McCormack wrote:
> > >> In article <t580j5$hlc$1...@dont-email.me>,
> > >> Andrey Tarasevich <andreyta...@hotmail.com> wrote:
> > >>> On 5/7/2022 9:45 PM, Dolores Filandro wrote:
> > >>>>
> > >>>>> {
> > >>>>> unsigned
> > >>>>> &l = *(unsigned *)left,
> > >>>>> &r = *(unsigned *)right;
> > >>>>> return l < r ? -1 : l > r ? 1 : 0;
> > >>>>> } );
> > >>>>
> > >>>>
> > >>>> (l > r ? 1 : 0) means exactly the same thing as (l > r)
> > >>>
> > >>> ... which is why one usually expresses the above as the idiomatic
> > >>>
> > >>> return (l > r) - (l < r);
> > >>
> > >> Which is why I've always thought it was dumb that the standard library
> > >> (both in C and in some "C-like" languages) doesn't provide the sgn()
> > >> function. It means that everybody has to re-invent the above idiom.
> > >>
> > >> Incidentally, is any of this necessary? I have not been following this
> > >> discussion, so I may have missed something, but if we are talking
> > >> about the
> > >> qsort() function, then it is not necessary to return exactly one of
> > >> -1, 0,
> > >> or 1. Any negative number will do, as will any positive one. So, all
> > >> you
> > >> need is (l-r).
> > >
> > > No. `l - r` is a major anti-pattern and is often a bug.
> > >
> > > Firstly, this will not work at all for unsigned types as in the original
> > > example. Secondly, in general this will not work for signed types since
> > > it can/will overflow.
> > >
> > > The only case when you can get away with `l - r` is smaller-than-int
> > > types (which are promoted to `int` and can't overflow), and situations
> > > where "you are absolutely sure" the values are so small that overflow
> > > can't happen.
> > >
> > > But it is not really worth it, when one has `(l > r) - (l < r)`.
> > Of course, one can always argue that `(l > r) - (l < r)` is also a
> > variation of `l - r` where the values are pre-normalized to ensure they
> > "are so small that overflow can't happen".
> > :O)
> >
> > --
> > Best regards,
> > Andrey
> But what I was getting at, is that
> for OP representing any relational or equality operator, ==, !=, >, <, et cetera,
> and with any text substitutions for A and B
> the expression ((A) OP (B)) means *Exactly* the same thing as the expression ((A) OP (B) ? 1 : 0)
> Same type
> Same value
> Same side effects
> to the extent that a compiler can always render the exact same op code for either expression.
>
The relational operators don't have to be overloaded to return a boolean.
It's normal to do so, but not required.
I suppose a use case would be a fuzzy logic type system whereby you could have
full or partial equality, and == returned a real on 0.0 - 1.0.

Re: The missing sgn() function

<878rra7crm.fsf@nosuchdomain.example.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=21631&group=comp.lang.c#21631

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: Keith.S....@gmail.com (Keith Thompson)
Newsgroups: comp.lang.c
Subject: Re: The missing sgn() function
Date: Mon, 09 May 2022 11:59:41 -0700
Organization: None to speak of
Lines: 14
Message-ID: <878rra7crm.fsf@nosuchdomain.example.com>
References: <t4092b$des$1@dont-email.me> <t40rkb$k2k$1@dont-email.me>
<72998849-f697-43e0-ad24-2cef111c8f36n@googlegroups.com>
<t580j5$hlc$1@dont-email.me> <t58m9r$3urcd$1@news.xmission.com>
<t58tdg$8q5$1@dont-email.me> <t58toa$ase$1@dont-email.me>
<05da37f2-818a-4ff5-a343-d7f500f37461n@googlegroups.com>
<cd0af991-5328-4605-bd53-3269a9ce3548n@googlegroups.com>
MIME-Version: 1.0
Content-Type: text/plain
Injection-Info: reader02.eternal-september.org; posting-host="cb6c391c454ddb02b2d990c3835aa6ea";
logging-data="16883"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19Pc73XzPUG0SCbrqTzBCWM"
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux)
Cancel-Lock: sha1:EiOxvXeuKRUU72GyddW+Ihx9hnw=
sha1:DvnU6KhTV4/LGDXINmXrUZTrdHo=
 by: Keith Thompson - Mon, 9 May 2022 18:59 UTC

Malcolm McLean <malcolm.arthur.mclean@gmail.com> writes:
[...]
> The relational operators don't have to be overloaded to return a boolean.
> It's normal to do so, but not required.
> I suppose a use case would be a fuzzy logic type system whereby you could have
> full or partial equality, and == returned a real on 0.0 - 1.0.

C doesn't have operator overloading. The equality and relational
operators return a result of type int with the value 0 or 1.

--
Keith Thompson (The_Other_Keith) Keith.S.Thompson+u@gmail.com
Working, but not speaking, for Philips
void Void(void) { Void(); } /* The recursive call of the void */

Re: qsort() vs. std::sort

<t5e3ca$cgo$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=21642&group=comp.lang.c#21642

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: Bonita.M...@gmail.com (Bonita Montero)
Newsgroups: comp.lang.c
Subject: Re: qsort() vs. std::sort
Date: Tue, 10 May 2022 18:21:00 +0200
Organization: A noiseless patient Spider
Lines: 14
Message-ID: <t5e3ca$cgo$1@dont-email.me>
References: <t4092b$des$1@dont-email.me>
<bb6cb651-6c86-49cc-bdee-83623c2bfb83n@googlegroups.com>
<t40rkb$k2k$1@dont-email.me>
<72998849-f697-43e0-ad24-2cef111c8f36n@googlegroups.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Tue, 10 May 2022 16:20:26 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="8415f35c0927941009d3256dd2af127d";
logging-data="12824"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/M5bsJJMSCa8i2fkj3p/wdU1SNkAtpX80="
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101
Thunderbird/91.9.0
Cancel-Lock: sha1:lQfXo/NnlGkWvGYEyHbBVvkjdeY=
In-Reply-To: <72998849-f697-43e0-ad24-2cef111c8f36n@googlegroups.com>
Content-Language: de-DE
 by: Bonita Montero - Tue, 10 May 2022 16:21 UTC

Am 08.05.2022 um 06:45 schrieb Dolores Filandro:
>
>> {
>> unsigned
>> &l = *(unsigned *)left,
>> &r = *(unsigned *)right;
>> return l < r ? -1 : l > r ? 1 : 0;
>> } );
>
>
> (l > r ? 1 : 0) means exactly the same thing as (l > r)

The result of the comparison-callback of qsort() is -1, 0 or 1.

Re: qsort() vs. std::sort

<wxweK.5437$Xh%d.4151@fx98.iad>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=21643&group=comp.lang.c#21643

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!usenet.blueworldhosting.com!feed1.usenet.blueworldhosting.com!peer01.iad!feed-me.highwinds-media.com!news.highwinds-media.com!fx98.iad.POSTED!not-for-mail
X-newsreader: xrn 9.03-beta-14-64bit
Sender: scott@dragon.sl.home (Scott Lurndal)
From: sco...@slp53.sl.home (Scott Lurndal)
Reply-To: slp53@pacbell.net
Subject: Re: qsort() vs. std::sort
Newsgroups: comp.lang.c
References: <t4092b$des$1@dont-email.me> <bb6cb651-6c86-49cc-bdee-83623c2bfb83n@googlegroups.com> <t40rkb$k2k$1@dont-email.me> <72998849-f697-43e0-ad24-2cef111c8f36n@googlegroups.com> <t5e3ca$cgo$1@dont-email.me>
Lines: 38
Message-ID: <wxweK.5437$Xh%d.4151@fx98.iad>
X-Complaints-To: abuse@usenetserver.com
NNTP-Posting-Date: Tue, 10 May 2022 16:37:48 UTC
Organization: UsenetServer - www.usenetserver.com
Date: Tue, 10 May 2022 16:37:48 GMT
X-Received-Bytes: 2322
 by: Scott Lurndal - Tue, 10 May 2022 16:37 UTC

Bonita Montero <Bonita.Montero@gmail.com> writes:
>Am 08.05.2022 um 06:45 schrieb Dolores Filandro:
>>
>>> {
>>> unsigned
>>> &l = *(unsigned *)left,
>>> &r = *(unsigned *)right;
>>> return l < r ? -1 : l > r ? 1 : 0;
>>> } );
>>
>>
>> (l > r ? 1 : 0) means exactly the same thing as (l > r)
>
>The result of the comparison-callback of qsort() is -1, 0 or 1.
>

Neither of the relevant standards agree with you.

C99 (n1256.pdf)

The comparison function pointed to by compar is called with two arguments that point
to the key object and to an array element, in that order. The function shall return an
integer less than, equal to, or greater than zero if the key object is considered,
respectively, to be less than, to match, or to be greater than the array element. The array
shall consist of: all the elements that compare less than, all the elements that compare
equal to, and all the elements that compare greater than the key object, in that order.264)

POSIX:

The contents of the array shall be sorted in ascending order according to a comparison
function. The compar argument is a pointer to the comparison function, which is
called with two arguments that point to the elements being compared. The
application shall ensure that the function returns an integer less than,
equal to, or greater than 0, if the first argument is considered respectively
less than, equal to, or greater than the second. If two members compare
as equal, their order in the sorted array is unspecified.

https://pubs.opengroup.org/onlinepubs/9699919799/functions/qsort.html

Re: qsort() vs. std::sort

<t5e71d$kvv$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=21644&group=comp.lang.c#21644

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: andreyta...@hotmail.com (Andrey Tarasevich)
Newsgroups: comp.lang.c
Subject: Re: qsort() vs. std::sort
Date: Tue, 10 May 2022 10:22:53 -0700
Organization: A noiseless patient Spider
Lines: 25
Message-ID: <t5e71d$kvv$1@dont-email.me>
References: <t4092b$des$1@dont-email.me>
<bb6cb651-6c86-49cc-bdee-83623c2bfb83n@googlegroups.com>
<t40rkb$k2k$1@dont-email.me>
<72998849-f697-43e0-ad24-2cef111c8f36n@googlegroups.com>
<t5e3ca$cgo$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Tue, 10 May 2022 17:22:54 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="4e763442b27f2d5a8a34d642be98f989";
logging-data="21503"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18mNOupDSm09pd4TZ4FXR0r"
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101
Thunderbird/91.9.0
Cancel-Lock: sha1:FM2pzfy5bGHZsk1cffYYIrQfXkg=
In-Reply-To: <t5e3ca$cgo$1@dont-email.me>
Content-Language: en-US
 by: Andrey Tarasevich - Tue, 10 May 2022 17:22 UTC

On 5/10/2022 9:21 AM, Bonita Montero wrote:
> Am 08.05.2022 um 06:45 schrieb Dolores Filandro:
>>
>>> {
>>> unsigned
>>> &l = *(unsigned *)left,
>>> &r = *(unsigned *)right;
>>> return l < r ? -1 : l > r ? 1 : 0;
>>> } );
>>
>>
>> (l > r ? 1 : 0)  means exactly the same thing as  (l > r)
>
> The result of the comparison-callback of qsort() is -1, 0 or 1.
>

What point are you trying to make? The result of `(l > r ? 1 : 0)` is 1
or 0. The result of `(l > r)` is also 1 or 0. So?

P.S. Notwithstanding that callback result does not have to be "-1, 0 or 1"

--
Best regards,
Andrey

Re: qsort() vs. std::sort

<t5fgqn$2d1$2@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=21646&group=comp.lang.c#21646

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: Bonita.M...@gmail.com (Bonita Montero)
Newsgroups: comp.lang.c
Subject: Re: qsort() vs. std::sort
Date: Wed, 11 May 2022 07:16:43 +0200
Organization: A noiseless patient Spider
Lines: 21
Message-ID: <t5fgqn$2d1$2@dont-email.me>
References: <t4092b$des$1@dont-email.me>
<bb6cb651-6c86-49cc-bdee-83623c2bfb83n@googlegroups.com>
<t40rkb$k2k$1@dont-email.me>
<72998849-f697-43e0-ad24-2cef111c8f36n@googlegroups.com>
<t5e3ca$cgo$1@dont-email.me> <wxweK.5437$Xh%d.4151@fx98.iad>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Wed, 11 May 2022 05:16:07 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="6cd0d5904402b4d50090497e12b98137";
logging-data="2465"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18TTG1CO+fnIoxoSkzvafbqvHEgc0bvtNY="
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101
Thunderbird/91.9.0
Cancel-Lock: sha1:ctblAVxAGGRvw4xHapDC7HlwFmU=
In-Reply-To: <wxweK.5437$Xh%d.4151@fx98.iad>
Content-Language: de-DE
 by: Bonita Montero - Wed, 11 May 2022 05:16 UTC

Am 10.05.2022 um 18:37 schrieb Scott Lurndal:
> Bonita Montero <Bonita.Montero@gmail.com> writes:
>> Am 08.05.2022 um 06:45 schrieb Dolores Filandro:
>>>
>>>> {
>>>> unsigned
>>>> &l = *(unsigned *)left,
>>>> &r = *(unsigned *)right;
>>>> return l < r ? -1 : l > r ? 1 : 0;
>>>> } );
>>>
>>>
>>> (l > r ? 1 : 0) means exactly the same thing as (l > r)
>>
>> The result of the comparison-callback of qsort() is -1, 0 or 1.
>>
>
> Neither of the relevant standards agree with you.

I'm not referring to the standard but what I implement.

Re: qsort() vs. std::sort

<t5fgs1$2d1$3@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=21647&group=comp.lang.c#21647

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: Bonita.M...@gmail.com (Bonita Montero)
Newsgroups: comp.lang.c
Subject: Re: qsort() vs. std::sort
Date: Wed, 11 May 2022 07:17:25 +0200
Organization: A noiseless patient Spider
Lines: 22
Message-ID: <t5fgs1$2d1$3@dont-email.me>
References: <t4092b$des$1@dont-email.me>
<bb6cb651-6c86-49cc-bdee-83623c2bfb83n@googlegroups.com>
<t40rkb$k2k$1@dont-email.me>
<72998849-f697-43e0-ad24-2cef111c8f36n@googlegroups.com>
<t5e3ca$cgo$1@dont-email.me> <t5e71d$kvv$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Wed, 11 May 2022 05:16:49 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="6cd0d5904402b4d50090497e12b98137";
logging-data="2465"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/jK5NtuGfjTgChO8CtruhoAVzkAdeZHMA="
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101
Thunderbird/91.9.0
Cancel-Lock: sha1:M4rHupAyUtoXXBI3qwWLElRD+6w=
In-Reply-To: <t5e71d$kvv$1@dont-email.me>
Content-Language: de-DE
 by: Bonita Montero - Wed, 11 May 2022 05:17 UTC

Am 10.05.2022 um 19:22 schrieb Andrey Tarasevich:
> On 5/10/2022 9:21 AM, Bonita Montero wrote:
>> Am 08.05.2022 um 06:45 schrieb Dolores Filandro:
>>>
>>>> {
>>>> unsigned
>>>> &l = *(unsigned *)left,
>>>> &r = *(unsigned *)right;
>>>> return l < r ? -1 : l > r ? 1 : 0;
>>>> } );
>>>
>>>
>>> (l > r ? 1 : 0)  means exactly the same thing as  (l > r)
>>
>> The result of the comparison-callback of qsort() is -1, 0 or 1.
>>
>
> What point are you trying to make? The result of `(l > r ? 1 : 0)` is 1
> or 0. The result of `(l > r)` is also 1 or 0. So?

Of course, but isn't a sufficient result for the qsort-callback.

Re: qsort() vs. std::sort

<9636e174-80c8-4757-a9a8-4f7ec5f4f4f5n@googlegroups.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=21649&group=comp.lang.c#21649

  copy link   Newsgroups: comp.lang.c
X-Received: by 2002:a37:695:0:b0:69f:b916:2d8e with SMTP id 143-20020a370695000000b0069fb9162d8emr18088932qkg.680.1652260493983;
Wed, 11 May 2022 02:14:53 -0700 (PDT)
X-Received: by 2002:a37:b605:0:b0:69e:6d6f:aea7 with SMTP id
g5-20020a37b605000000b0069e6d6faea7mr18084736qkf.655.1652260493847; Wed, 11
May 2022 02:14:53 -0700 (PDT)
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!usenet.blueworldhosting.com!feed1.usenet.blueworldhosting.com!peer01.iad!feed-me.highwinds-media.com!news.highwinds-media.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.c
Date: Wed, 11 May 2022 02:14:53 -0700 (PDT)
In-Reply-To: <t5fgs1$2d1$3@dont-email.me>
Injection-Info: google-groups.googlegroups.com; posting-host=84.50.190.130; posting-account=pysjKgkAAACLegAdYDFznkqjgx_7vlUK
NNTP-Posting-Host: 84.50.190.130
References: <t4092b$des$1@dont-email.me> <bb6cb651-6c86-49cc-bdee-83623c2bfb83n@googlegroups.com>
<t40rkb$k2k$1@dont-email.me> <72998849-f697-43e0-ad24-2cef111c8f36n@googlegroups.com>
<t5e3ca$cgo$1@dont-email.me> <t5e71d$kvv$1@dont-email.me> <t5fgs1$2d1$3@dont-email.me>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <9636e174-80c8-4757-a9a8-4f7ec5f4f4f5n@googlegroups.com>
Subject: Re: qsort() vs. std::sort
From: oot...@hot.ee (Öö Tiib)
Injection-Date: Wed, 11 May 2022 09:14:53 +0000
Content-Type: text/plain; charset="UTF-8"
X-Received-Bytes: 2274
 by: Öö Tiib - Wed, 11 May 2022 09:14 UTC

On Wednesday, 11 May 2022 at 08:17:02 UTC+3, Bonita Montero wrote:
> Am 10.05.2022 um 19:22 schrieb Andrey Tarasevich:
> > On 5/10/2022 9:21 AM, Bonita Montero wrote:
> >> Am 08.05.2022 um 06:45 schrieb Dolores Filandro:
> >>>
> >>>> {
> >>>> unsigned
> >>>> &l = *(unsigned *)left,
> >>>> &r = *(unsigned *)right;
> >>>> return l < r ? -1 : l > r ? 1 : 0;
> >>>> } );
> >>>
> >>>
> >>> (l > r ? 1 : 0) means exactly the same thing as (l > r)
> >>
> >> The result of the comparison-callback of qsort() is -1, 0 or 1.
> >>
> >
> > What point are you trying to make? The result of `(l > r ? 1 : 0)` is 1
> > or 0. The result of `(l > r)` is also 1 or 0. So?
> Of course, but isn't a sufficient result for the qsort-callback.

The qsort does not require you to write redundant code in callback.
The "l > r ? 1 : 0" you are discussing is subexpression that is exactly
equivalent with "l > r" so the "? 1 : 0" part of it is superfluous.

Re: qsort() vs. std::sort

<871671e2-6d81-4b37-b1d2-31d54f6c62a2n@googlegroups.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=21650&group=comp.lang.c#21650

  copy link   Newsgroups: comp.lang.c
X-Received: by 2002:a05:620a:10b2:b0:69f:9e8d:33eb with SMTP id h18-20020a05620a10b200b0069f9e8d33ebmr18732101qkk.111.1652279184839;
Wed, 11 May 2022 07:26:24 -0700 (PDT)
X-Received: by 2002:a05:620a:99a:b0:69f:8204:d8de with SMTP id
x26-20020a05620a099a00b0069f8204d8demr18982922qkx.58.1652279184601; Wed, 11
May 2022 07:26:24 -0700 (PDT)
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!usenet.blueworldhosting.com!feed1.usenet.blueworldhosting.com!peer01.iad!feed-me.highwinds-media.com!news.highwinds-media.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.c
Date: Wed, 11 May 2022 07:26:24 -0700 (PDT)
In-Reply-To: <t5fgs1$2d1$3@dont-email.me>
Injection-Info: google-groups.googlegroups.com; posting-host=108.45.179.220; posting-account=Ix1u_AoAAAAILVQeRkP2ENwli-Uv6vO8
NNTP-Posting-Host: 108.45.179.220
References: <t4092b$des$1@dont-email.me> <bb6cb651-6c86-49cc-bdee-83623c2bfb83n@googlegroups.com>
<t40rkb$k2k$1@dont-email.me> <72998849-f697-43e0-ad24-2cef111c8f36n@googlegroups.com>
<t5e3ca$cgo$1@dont-email.me> <t5e71d$kvv$1@dont-email.me> <t5fgs1$2d1$3@dont-email.me>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <871671e2-6d81-4b37-b1d2-31d54f6c62a2n@googlegroups.com>
Subject: Re: qsort() vs. std::sort
From: jameskuy...@alumni.caltech.edu (james...@alumni.caltech.edu)
Injection-Date: Wed, 11 May 2022 14:26:24 +0000
Content-Type: text/plain; charset="UTF-8"
X-Received-Bytes: 2439
 by: james...@alumni.calt - Wed, 11 May 2022 14:26 UTC

On Wednesday, May 11, 2022 at 1:17:02 AM UTC-4, Bonita Montero wrote:
> Am 10.05.2022 um 19:22 schrieb Andrey Tarasevich:
> > On 5/10/2022 9:21 AM, Bonita Montero wrote:
> >> Am 08.05.2022 um 06:45 schrieb Dolores Filandro:
> >>>
> >>>> {
> >>>> unsigned
> >>>> &l = *(unsigned *)left,
> >>>> &r = *(unsigned *)right;
> >>>> return l < r ? -1 : l > r ? 1 : 0;
> >>>> } );
> >>>
> >>>
> >>> (l > r ? 1 : 0) means exactly the same thing as (l > r)
> >>
> >> The result of the comparison-callback of qsort() is -1, 0 or 1.
> >>
> >
> > What point are you trying to make? The result of `(l > r ? 1 : 0)` is 1
> > or 0. The result of `(l > r)` is also 1 or 0. So?
> Of course, but isn't a sufficient result for the qsort-callback.

No one suggested that it was. The original code was

return l < r ? -1 : l > r ? 1 : 0;

Doloros was pointing out that the sub-expression l > r ? 1 : 0 was
exactly equivalent to l > r, implying that the code should be changed to

return l < r ? -1 : l > r;

No on was suggesting that it be changed to

return l > r;

Re: qsort() vs. std::sort

<t5gijk$8bg$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=21651&group=comp.lang.c#21651

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: Bonita.M...@gmail.com (Bonita Montero)
Newsgroups: comp.lang.c
Subject: Re: qsort() vs. std::sort
Date: Wed, 11 May 2022 16:53:12 +0200
Organization: A noiseless patient Spider
Lines: 7
Message-ID: <t5gijk$8bg$1@dont-email.me>
References: <t4092b$des$1@dont-email.me>
<bb6cb651-6c86-49cc-bdee-83623c2bfb83n@googlegroups.com>
<t40rkb$k2k$1@dont-email.me>
<72998849-f697-43e0-ad24-2cef111c8f36n@googlegroups.com>
<t5e3ca$cgo$1@dont-email.me> <t5e71d$kvv$1@dont-email.me>
<t5fgs1$2d1$3@dont-email.me>
<9636e174-80c8-4757-a9a8-4f7ec5f4f4f5n@googlegroups.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Wed, 11 May 2022 14:52:36 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="6cd0d5904402b4d50090497e12b98137";
logging-data="8560"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18mXwknZ98n2BtecPFKIawIvZOWgM3t6bA="
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101
Thunderbird/91.9.0
Cancel-Lock: sha1:AS8aOKvLwR4n/bcRpg+MtNtKoqI=
In-Reply-To: <9636e174-80c8-4757-a9a8-4f7ec5f4f4f5n@googlegroups.com>
Content-Language: de-DE
 by: Bonita Montero - Wed, 11 May 2022 14:53 UTC

> The qsort does not require you to write redundant code in callback.
> The "l > r ? 1 : 0" you are discussing is subexpression that is exactly
> equivalent with "l > r" so the "? 1 : 0" part of it is superfluous.

Right, but that's not what qsort needs. qsort doesn't need a less
-predicate like std::sort but a ternary result which is either
negative, zero or positive.

Re: qsort() vs. std::sort

<c62eb752-b9ce-4f60-84e9-42ef71195b95n@googlegroups.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=21653&group=comp.lang.c#21653

  copy link   Newsgroups: comp.lang.c
X-Received: by 2002:ac8:5bd0:0:b0:2f3:bb55:4612 with SMTP id b16-20020ac85bd0000000b002f3bb554612mr24768853qtb.391.1652285626404;
Wed, 11 May 2022 09:13:46 -0700 (PDT)
X-Received: by 2002:a05:622a:148:b0:2f3:e454:760 with SMTP id
v8-20020a05622a014800b002f3e4540760mr7643550qtw.543.1652285626227; Wed, 11
May 2022 09:13:46 -0700 (PDT)
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!usenet.blueworldhosting.com!feed1.usenet.blueworldhosting.com!peer01.iad!feed-me.highwinds-media.com!news.highwinds-media.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.c
Date: Wed, 11 May 2022 09:13:46 -0700 (PDT)
In-Reply-To: <t5gijk$8bg$1@dont-email.me>
Injection-Info: google-groups.googlegroups.com; posting-host=108.45.179.220; posting-account=Ix1u_AoAAAAILVQeRkP2ENwli-Uv6vO8
NNTP-Posting-Host: 108.45.179.220
References: <t4092b$des$1@dont-email.me> <bb6cb651-6c86-49cc-bdee-83623c2bfb83n@googlegroups.com>
<t40rkb$k2k$1@dont-email.me> <72998849-f697-43e0-ad24-2cef111c8f36n@googlegroups.com>
<t5e3ca$cgo$1@dont-email.me> <t5e71d$kvv$1@dont-email.me> <t5fgs1$2d1$3@dont-email.me>
<9636e174-80c8-4757-a9a8-4f7ec5f4f4f5n@googlegroups.com> <t5gijk$8bg$1@dont-email.me>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <c62eb752-b9ce-4f60-84e9-42ef71195b95n@googlegroups.com>
Subject: Re: qsort() vs. std::sort
From: jameskuy...@alumni.caltech.edu (james...@alumni.caltech.edu)
Injection-Date: Wed, 11 May 2022 16:13:46 +0000
Content-Type: text/plain; charset="UTF-8"
X-Received-Bytes: 2113
 by: james...@alumni.calt - Wed, 11 May 2022 16:13 UTC

On Wednesday, May 11, 2022 at 10:52:51 AM UTC-4, Bonita Montero wrote:
> > The qsort does not require you to write redundant code in callback.
> > The "l > r ? 1 : 0" you are discussing is subexpression that is exactly
> > equivalent with "l > r" so the "? 1 : 0" part of it is superfluous.
> Right, but that's not what qsort needs. qsort doesn't need a less
> -predicate like std::sort but a ternary result which is either
> negative, zero or positive.

Which is precisely what you get with either

return l < r ? -1 : l > r ? 1 : 0;,

as you originally wrote it, or with l > r ? 1 : 0 simplified to l > r, giving

return l < r ? -1 : l > r;

as was implicitly by Dolores' comment.

Re: qsort() vs. std::sort

<t5gp4p$h7o$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=21654&group=comp.lang.c#21654

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: Bonita.M...@gmail.com (Bonita Montero)
Newsgroups: comp.lang.c
Subject: Re: qsort() vs. std::sort
Date: Wed, 11 May 2022 18:44:44 +0200
Organization: A noiseless patient Spider
Lines: 21
Message-ID: <t5gp4p$h7o$1@dont-email.me>
References: <t4092b$des$1@dont-email.me>
<bb6cb651-6c86-49cc-bdee-83623c2bfb83n@googlegroups.com>
<t40rkb$k2k$1@dont-email.me>
<72998849-f697-43e0-ad24-2cef111c8f36n@googlegroups.com>
<t5e3ca$cgo$1@dont-email.me> <t5e71d$kvv$1@dont-email.me>
<t5fgs1$2d1$3@dont-email.me>
<9636e174-80c8-4757-a9a8-4f7ec5f4f4f5n@googlegroups.com>
<t5gijk$8bg$1@dont-email.me>
<c62eb752-b9ce-4f60-84e9-42ef71195b95n@googlegroups.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Wed, 11 May 2022 16:44:09 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="6cd0d5904402b4d50090497e12b98137";
logging-data="17656"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/YDwMdGrSMIKhUxIFntEPRd2u+xMkEGlM="
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101
Thunderbird/91.9.0
Cancel-Lock: sha1:EylyhRmwkyaIYUZJcfp+PEDbJlE=
In-Reply-To: <c62eb752-b9ce-4f60-84e9-42ef71195b95n@googlegroups.com>
Content-Language: de-DE
 by: Bonita Montero - Wed, 11 May 2022 16:44 UTC

Am 11.05.2022 um 18:13 schrieb james...@alumni.caltech.edu:
> On Wednesday, May 11, 2022 at 10:52:51 AM UTC-4, Bonita Montero wrote:
>>> The qsort does not require you to write redundant code in callback.
>>> The "l > r ? 1 : 0" you are discussing is subexpression that is exactly
>>> equivalent with "l > r" so the "? 1 : 0" part of it is superfluous.
>> Right, but that's not what qsort needs. qsort doesn't need a less
>> -predicate like std::sort but a ternary result which is either
>> negative, zero or positive.
>
> Which is precisely what you get with either
>
> return l < r ? -1 : l > r ? 1 : 0;,
>
> as you originally wrote it, or with l > r ? 1 : 0 simplified to l > r, giving
>
> return l < r ? -1 : l > r;
>
> as was implicitly by Dolores' comment.

The optimizer generates the same code and mine is more readable.

Re: qsort() vs. std::sort

<08fb7368-e29e-4b7f-a476-eb014a491792n@googlegroups.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=21655&group=comp.lang.c#21655

  copy link   Newsgroups: comp.lang.c
X-Received: by 2002:a37:a90e:0:b0:69f:9b8f:86b4 with SMTP id s14-20020a37a90e000000b0069f9b8f86b4mr20050230qke.513.1652323231570;
Wed, 11 May 2022 19:40:31 -0700 (PDT)
X-Received: by 2002:a05:622a:349:b0:2f3:cba9:242c with SMTP id
r9-20020a05622a034900b002f3cba9242cmr25156199qtw.50.1652323231376; Wed, 11
May 2022 19:40:31 -0700 (PDT)
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!usenet.blueworldhosting.com!feed1.usenet.blueworldhosting.com!peer03.iad!feed-me.highwinds-media.com!news.highwinds-media.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.c
Date: Wed, 11 May 2022 19:40:31 -0700 (PDT)
In-Reply-To: <t5gp4p$h7o$1@dont-email.me>
Injection-Info: google-groups.googlegroups.com; posting-host=108.45.179.220; posting-account=Ix1u_AoAAAAILVQeRkP2ENwli-Uv6vO8
NNTP-Posting-Host: 108.45.179.220
References: <t4092b$des$1@dont-email.me> <bb6cb651-6c86-49cc-bdee-83623c2bfb83n@googlegroups.com>
<t40rkb$k2k$1@dont-email.me> <72998849-f697-43e0-ad24-2cef111c8f36n@googlegroups.com>
<t5e3ca$cgo$1@dont-email.me> <t5e71d$kvv$1@dont-email.me> <t5fgs1$2d1$3@dont-email.me>
<9636e174-80c8-4757-a9a8-4f7ec5f4f4f5n@googlegroups.com> <t5gijk$8bg$1@dont-email.me>
<c62eb752-b9ce-4f60-84e9-42ef71195b95n@googlegroups.com> <t5gp4p$h7o$1@dont-email.me>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <08fb7368-e29e-4b7f-a476-eb014a491792n@googlegroups.com>
Subject: Re: qsort() vs. std::sort
From: jameskuy...@alumni.caltech.edu (james...@alumni.caltech.edu)
Injection-Date: Thu, 12 May 2022 02:40:31 +0000
Content-Type: text/plain; charset="UTF-8"
X-Received-Bytes: 2426
 by: james...@alumni.calt - Thu, 12 May 2022 02:40 UTC

On Wednesday, May 11, 2022 at 12:44:23 PM UTC-4, Bonita Montero wrote:
> Am 11.05.2022 um 18:13 schrieb james...@alumni.caltech.edu:
....
> > Which is precisely what you get with either
> >
> > return l < r ? -1 : l > r ? 1 : 0;,
> >
> > as you originally wrote it, or with l > r ? 1 : 0 simplified to l > r, giving
> >
> > return l < r ? -1 : l > r;
> >
> > as was implicitly by Dolores' comment.
> The optimizer generates the same code and mine is more readable.

Readability is a judgment call, and I've learned there's not much point in
arguing about judgment calls. Dolores' is simpler, and to me, at least, more
readable. Code like yours would make me wonder whether the author was
so unfamiliar with C that she didn't realize the extra complication was
unnecessary. It wouldn't occur to me to think she might have written it
because she found the unnecessarily complicated code more readable.

Re: qsort() vs. std::sort

<t5i1vr$m3k$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=21656&group=comp.lang.c#21656

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: Bonita.M...@gmail.com (Bonita Montero)
Newsgroups: comp.lang.c
Subject: Re: qsort() vs. std::sort
Date: Thu, 12 May 2022 06:21:51 +0200
Organization: A noiseless patient Spider
Lines: 13
Message-ID: <t5i1vr$m3k$1@dont-email.me>
References: <t4092b$des$1@dont-email.me>
<bb6cb651-6c86-49cc-bdee-83623c2bfb83n@googlegroups.com>
<t40rkb$k2k$1@dont-email.me>
<72998849-f697-43e0-ad24-2cef111c8f36n@googlegroups.com>
<t5e3ca$cgo$1@dont-email.me> <t5e71d$kvv$1@dont-email.me>
<t5fgs1$2d1$3@dont-email.me>
<9636e174-80c8-4757-a9a8-4f7ec5f4f4f5n@googlegroups.com>
<t5gijk$8bg$1@dont-email.me>
<c62eb752-b9ce-4f60-84e9-42ef71195b95n@googlegroups.com>
<t5gp4p$h7o$1@dont-email.me>
<08fb7368-e29e-4b7f-a476-eb014a491792n@googlegroups.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Thu, 12 May 2022 04:21:15 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="49e9c1cfd9c24c899de872568df040e3";
logging-data="22644"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+CTgMqUkEqIzktjzaK6dNsgicLIVUako4="
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101
Thunderbird/91.9.0
Cancel-Lock: sha1:jtdN95SwQlf3mTXBLFUgcrKC724=
In-Reply-To: <08fb7368-e29e-4b7f-a476-eb014a491792n@googlegroups.com>
Content-Language: de-DE
 by: Bonita Montero - Thu, 12 May 2022 04:21 UTC

> Readability is a judgment call, ...

I think most people generally understanding code would argue like that.

> Dolores' is simpler, ...

Less code, not simpler.

> Code like yours would make me wonder whether the author was
> so unfamiliar with C that she didn't realize the extra complication

It's less complication.

Pages:12
server_pubkey.txt

rocksolid light 0.9.8
clearnet tor