Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.c > #149802
| Path | csiph.com!news.swapon.de!eternal-september.org!feeder.eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail |
|---|---|
| From | Keith Thompson <Keith.S.Thompson+u@gmail.com> |
| Newsgroups | comp.lang.c |
| Subject | Re: template(ish) qsort() function possible in language standard? |
| Date | Thu, 06 Feb 2020 13:20:52 -0800 |
| Organization | None to speak of |
| Lines | 42 |
| Message-ID | <87v9oj1kgb.fsf@nosuchdomain.example.com> (permalink) |
| References | <r1f8cm$3mj$1@dont-email.me> <k3nm3ftes9vmbfci9telkmk44p2grtl79u@4ax.com> <r1hkc1$uvd$1@dont-email.me> |
| Mime-Version | 1.0 |
| Content-Type | text/plain |
| Injection-Info | reader02.eternal-september.org; posting-host="9c63a4a0e1f252b3c684a24aa8868c59"; logging-data="29806"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18OpEV1xKvDweH5aMwJo0oP" |
| User-Agent | Gnus/5.13 (Gnus v5.13) Emacs/26.3 (gnu/linux) |
| Cancel-Lock | sha1:ApDjKrx/RT2ezQkFZVJoOsuVerQ= sha1:4Lsz7Duw6IeJRGa2cenkBrNqDWs= |
| Xref | csiph.com comp.lang.c:149802 |
Show key headers only | View raw
mathog <dmathog@gmail.com> writes:
[...]
> In a similar vein, there is no memswap(), analogous to memcpy() or
> memmove(). For the example above:
>
> memswap(*(p+k), *(p+k+size), sizeof(char));
>
> Dogma has it that memswap() isn't needed very often, so it need not be
> part of the language. (Overlaps would also be an issue, with my vote
> being that overlaps would be a fatal error.)
What exactly do you mean by "fatal error"? Detecting overlap at
compile time is in general not possible. Detecting overlap at run
time would add overhead; the compiler would have to generate code
to compare the addresses and size (almost certainly in a manner
that would not be guaranteed to work in user-written code).
memcpy() has undefined behavior on overlap.
If copying takes place between objects that overlap, the behavior is
undefined.
If memswap() were standardized, it would make sense to do the same
thing.
Note that memcpy()ing an object to itself has undefined behavior, though
I'd guess that it works as expected in most or all implementations.
> One would hope that if
> it is ever added the language spec would require that for maximum
> efficiency implementations use native types whenever possible, so for
> sizes 1,2,4,8, probably 16, and maybe 32 or higher, only falling back
> to a more general form for other sizes, or if the third parameter is a
> variable.
I would hope that the language spec would leave it up to implementations
to optimize it as they choose, as it does now for memcpy().
--
Keith Thompson (The_Other_Keith) Keith.S.Thompson+u@gmail.com
Working, but not speaking, for Philips Healthcare
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
template(ish) qsort() function possible in language standard? mathog <dmathog@gmail.com> - 2020-02-05 12:25 -0800
Re: template(ish) qsort() function possible in language standard? Robert Wessel <robertwessel2@yahoo.com> - 2020-02-05 18:25 -0600
Re: template(ish) qsort() function possible in language standard? mathog <dmathog@gmail.com> - 2020-02-06 10:02 -0800
Re: template(ish) qsort() function possible in language standard? Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2020-02-06 13:20 -0800
Re: template(ish) qsort() function possible in language standard? mathog <dmathog@gmail.com> - 2020-02-06 15:24 -0800
Re: template(ish) qsort() function possible in language standard? Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2020-02-06 15:38 -0800
Re: template(ish) qsort() function possible in language standard? Bonita Montero <Bonita.Montero@gmail.com> - 2020-02-06 20:56 +0100
Re: template(ish) qsort() function possible in language standard? Anton Shepelev <anton.txt@gmail.com> - 2020-02-08 17:50 +0300
csiph-web