memcpy

Henry Spencer henry at zoo.toronto.edu
Fri Sep 21 13:11:42 AEST 1990


In article <1990Sep19.021418.11574 at maths.tcd.ie> tim at maths.tcd.ie (Timothy Murphy) writes:
>In unzip.c it is assumed that the effect of
>	buf[0] = c;
>	memcpy(buf+1, buf, 20);
>is to set
>	buf[0] = buf[1] = buf[2] = ... = buf[21] = c.

The effects of invoking memcpy with overlapping operands have never been
officially promised, that I recall.  ANSI C explicitly says that the
implementation is allowed to assume that they do not overlap, and it
is the programmer's responsibility to assure this.

This sounds like rank-amateur code.  If he wants to set all characters
in a buffer to the same, memset() will do that efficiently and cleanly.
Even if an overlapping memcpy() works, it is not going to be particularly
fast.
-- 
TCP/IP: handling tomorrow's loads today| Henry Spencer at U of Toronto Zoology
OSI: handling yesterday's loads someday|  henry at zoo.toronto.edu   utzoo!henry



More information about the Comp.std.c mailing list