Newsgroups: comp.std.c Path: utzoo!henry From: henry@zoo.toronto.edu (Henry Spencer) Subject: Re: memcpy Message-ID: <1990Sep21.031142.23718@zoo.toronto.edu> Organization: U of Toronto Zoology References: <1990Sep19.021418.11574@maths.tcd.ie> Date: Fri, 21 Sep 90 03:11:42 GMT In article <1990Sep19.021418.11574@maths.tcd.ie> tim@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@zoo.toronto.edu utzoo!henry