Liste des Groupes | Revenir à c arch |
mitchalsup@aol.com (MitchAlsup1) writes:What really worries me is that I've been told (and shown in godbolt) that memcpy() can be magic, i.e the ocmpiler is allowed to make it NOP when I use it to move data between an integer and float variable:
On Wed, 4 Sep 2024 17:53:13 +0000, David Brown wrote:The ever-shallow David Brown first misses the point, then makes a
>On 04/09/2024 18:07, Tim Rentsch wrote:
>Terje Mathisen <terje.mathisen@tmsw.no> writes:>
>Michael S wrote:>
>On Tue, 3 Sep 2024 17:41:40 +0200>
Terje Mathisen <terje.mathisen@tmsw.no> wrote:
>Michael S wrote:>
>3 years ago Terje Mathisen wrote that many years ago he read>
that behaviour of memcpy() with overlappped src/dst was defined.
https://groups.google.com/g/comp.arch/c/rSk8c7Urd_Y/m/ZWEG5V1KAQAJ
Mitch Alsup answered "That was true in 1983". So, two people of
different age living in different parts of the world are telling
the same story. May be, there exist old popular book that said
that it was defined?
It probably wasn't written in the official C standard, which I
couldn't have afforded to buy/read, but in a compiler runtime
doc?
>
Specifying that it would always copy from beginning to end of
the source buffer, in increasing address order meant that it
was guaranteed safe when used to compact buffers.
What is "compact buffers" ?
Assume a buffer consisting of records of some type, some of
them marked as deleted. Iterating over them while removing
the gaps means that you are always copying to a destination
lower in memory, right?
If all the records are in one large array, there is a simple
test to see if memcpy() must work or whether some alternative
should be used instead.
Such tests are usually built into implementations of memmove(),
which will chose to run forwards or backwards as needed. So you
might as well just call memmove() any time you are not sure
memcpy() is safe and appropriate.
slightly incorrect statement, and finally makes a recommendation
that surely is familiar to every reader in the newsgroup.
Memmove() is always appropriate unless you are doing somethingIncidentally, if one wants to do this, it's advisable to write
nefarious.
>
So:
# define memcpy memomve
#undef memcpy
before the #define of memcpy.
Les messages affichés proviennent d'usenet.