Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
| Path | csiph.com!eternal-september.org!feeder.eternal-september.org!mx02.eternal-september.org!.POSTED!not-for-mail |
|---|---|
| From | Keith Thompson <kst-u@mib.org> |
| Newsgroups | comp.lang.c |
| Subject | Re: the language (and the role of Undefined Behavior therein) |
| Date | Sat, 31 Oct 2015 13:53:15 -0700 |
| Organization | None to speak of |
| Lines | 35 |
| Message-ID | <ln37wq92v8.fsf@kst-u.example.com> (permalink) |
| References | <lnbne014z3.fsf@kst-u.example.com> <kfnwpw2mfh4.fsf@x-alumni2.alumni.caltech.edu> <ad139439-52f1-4ff0-9f74-58cd6d0b8bc5@googlegroups.com> <kfn1tda6vbp.fsf@x-alumni2.alumni.caltech.edu> <d0caa5eb-5189-46a7-b6d0-84e82f59b199@googlegroups.com> <musvis$1j0$1@speranza.aioe.org> <877fn1lc3f.fsf@bsb.me.uk> <muu4qu$pqj$1@speranza.aioe.org> <87wpv1jh23.fsf@bsb.me.uk> <muus8j$k62$1@speranza.aioe.org> <87vbak9uto.fsf@bsb.me.uk> <2b01d4e3-5a2c-4800-9c00-fc3430aef7b2@googlegroups.com> <ns693bdm24s72ejvujbvusr3oqfuvd4fln@4ax.com> <84c2bc9f-bd27-46b7-a4b3-0f291787d28e@googlegroups.com> |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset=us-ascii |
| Injection-Info | mx02.eternal-september.org; posting-host="945944de09706c9b4e29b53c9d2efdc2"; logging-data="26907"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX182y0b2itEUabYGiJdmO9Xs" |
| User-Agent | Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux) |
| Cancel-Lock | sha1:ol1Kvd/iP4HdA+KNwJmMBDfG1HE= sha1:HUW6KF12t5WTSIr7/r3NNgF8zGc= |
| Xref | csiph.com comp.lang.c:74495 |
Show key headers only | View raw
supercat@casperkitty.com writes:
[...]
> I do dislike the prohibition on memcpy being passed the same argument for
> src and dest along with a non-zero size, however, since a lot of compilers
> do a better job of optimizing memcpy than memmove, and given code like:
>
> void copyLong2(long *dest, long *src)
> {
> if (dest != src)
> memcpy(dest, src, sizeof *dest);
> }
>
> a compiler could only optimize away the comparison if it could prove that
> it was impossible for dest and src to both be null (since calling copyLong2
> with two null pointers would be a defined safe no-op, but reading and
> writing a null pointer would not be.)
[...]
A compiler could optimize away the comparison if it knows that
memcpy(foo, foo, non_zero)
is safe *for that implementation*. Since memcpy is part of the
standard library and therefore part of the implementation, a compiler
may take advantage of any knowledge it has about its behavior.
A compiler designed to work with different runtime libraries could
not in general assume anything beyond what the standard guarantees
-- but a particular implementation of <string.h> might include
gcc-specific code that could provide extra information to gcc and
be ignored by other compilers.
--
Keith Thompson (The_Other_Keith) kst-u@mib.org <http://www.ghoti.net/~kst>
Working, but not speaking, for JetHead Development, Inc.
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
Back to comp.lang.c | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Re: the language (and the role of Undefined Behavior therein) supercat@casperkitty.com - 2015-09-29 15:48 -0700
Re: the language (and the role of Undefined Behavior therein) Tim Rentsch <txr@alumni.caltech.edu> - 2015-10-04 16:57 -0700
Re: the language (and the role of Undefined Behavior therein) supercat@casperkitty.com - 2015-10-04 19:48 -0700
Re: the language (and the role of Undefined Behavior therein) glen herrmannsfeldt <gah@ugcs.caltech.edu> - 2015-10-05 04:50 +0000
Re: the language (and the role of Undefined Behavior therein) Ben Bacarisse <ben.usenet@bsb.me.uk> - 2015-10-05 13:43 +0100
Re: the language (and the role of Undefined Behavior therein) glen herrmannsfeldt <gah@ugcs.caltech.edu> - 2015-10-05 15:26 +0000
Re: the language (and the role of Undefined Behavior therein) Ben Bacarisse <ben.usenet@bsb.me.uk> - 2015-10-05 19:39 +0100
Re: the language (and the role of Undefined Behavior therein) supercat@casperkitty.com - 2015-10-05 13:32 -0700
Re: the language (and the role of Undefined Behavior therein) glen herrmannsfeldt <gah@ugcs.caltech.edu> - 2015-10-05 22:06 +0000
Re: the language (and the role of Undefined Behavior therein) supercat@casperkitty.com - 2015-10-05 16:08 -0700
Re: the language (and the role of Undefined Behavior therein) Ben Bacarisse <ben.usenet@bsb.me.uk> - 2015-10-06 11:04 +0100
Re: the language (and the role of Undefined Behavior therein) supercat@casperkitty.com - 2015-10-06 08:06 -0700
Re: the language (and the role of Undefined Behavior therein) Rosario19 <Ros@invalid.invalid> - 2015-10-06 18:14 +0200
Re: the language (and the role of Undefined Behavior therein) Rosario19 <Ros@invalid.invalid> - 2015-10-06 18:54 +0200
Re: the language (and the role of Undefined Behavior therein) supercat@casperkitty.com - 2015-10-06 11:20 -0700
Re: the language (and the role of Undefined Behavior therein) supercat@casperkitty.com - 2015-10-06 10:00 -0700
Re: the language (and the role of Undefined Behavior therein) David Thompson <dave.thompson2@verizon.net> - 2015-10-31 06:44 -0400
Re: the language (and the role of Undefined Behavior therein) supercat@casperkitty.com - 2015-10-31 11:08 -0700
Re: the language (and the role of Undefined Behavior therein) Keith Thompson <kst-u@mib.org> - 2015-10-31 13:53 -0700
Re: the language (and the role of Undefined Behavior therein) supercat@casperkitty.com - 2015-10-31 14:06 -0700
Re: the language (and the role of Undefined Behavior therein) supercat@casperkitty.com - 2015-10-05 09:28 -0700
Re: the language (and the role of Undefined Behavior therein) Keith Thompson <kst-u@mib.org> - 2015-10-05 11:20 -0700
Re: the language (and the role of Undefined Behavior therein) Ben Bacarisse <ben.usenet@bsb.me.uk> - 2015-10-05 20:13 +0100
Re: the language (and the role of Undefined Behavior therein) Tim Rentsch <txr@alumni.caltech.edu> - 2015-10-12 09:29 -0700
Re: the language (and the role of Undefined Behavior therein) Tim Rentsch <txr@alumni.caltech.edu> - 2015-10-12 10:32 -0700
Re: the language (and the role of Undefined Behavior therein) supercat@casperkitty.com - 2015-10-12 12:23 -0700
Re: the language (and the role of Undefined Behavior therein) supercat@casperkitty.com - 2015-10-12 14:42 -0700
Re: the language (and the role of Undefined Behavior therein) supercat@casperkitty.com - 2015-10-14 09:10 -0700
Re: the language (and the role of Undefined Behavior therein) Tim Rentsch <txr@alumni.caltech.edu> - 2015-10-19 16:11 -0700
csiph-web