Just a quick comment than Jan-Benedict's opinion is widely shared by the specification and by the Linux glibc manpage:

DESCRIPTION
The memcpy() function copies n bytes from memory area src to memory area dest. The memory areas should not overlap. Use memmove(3) if the
       memory areas do overlap.

It doesn't matter if it sometimes works. Sometimes works programs are sometimes doesn't work programs. :-)

Cheers,
mark

On 04/30/2010 10:25 AM, Jan-Benedict Glaw wrote:
On Fri, 2010-04-30 16:14:36 +0200, Joakim 
Tjernlund<joakim.tjernl...@transmode.se>  wrote:
Jan-Benedict Glaw<jbg...@lug-owl.de>  wrote on 2010/04/30 16:10:42:
On Fri, 2010-04-30 16:08:15 +0200, Joakim Tjernlund
<joakim.tjernl...@transmode.se>  wrote:
Is memcpy supposed to work when the src and dest are the same:
memcpy(p, p, 100);
It may work, but you cannot rely on it. Use memmove() alternatively.
My view too, but gcc 3.4.6 on gcc does this:
[...]

Surely, it may/will work here and there. But it's not portable :)  And
I won't rely on a "it worked once" fact.

MfG, JBG


Reply via email to