[comp.lang.c] strcpy: "after the null has been copied"

mouse@mcgill-vision.UUCP (der Mouse) (04/08/88)

In article <793@cresswell.quintus.UUCP>, ok@quintus.UUCP (Richard A. O'Keefe) writes:
> The UNIX manuals say of strcpy(s1, s2) that it
> "copies s2 to s1, stopping after the null character has been copied."
> While they doesn't strictly speaking say anything about the order in
> which the other characters are copied, they _do_ say that the NUL
> character must be copied last,

Ah, but they don't.  A strict interpretation would take your quote as
meaning nothing more than that strcpy is guaranteed to copy the null,
because it is specified that it won't stop before that, and does say
that it stops (after that).  Nothing is said (by the above quote) about
whether it copies anything after the null, or whether it does the null
(temporally) first, last, or somewhere in between.  There is a strong
implication that either (a) it doesn't copy the character after the
null or (b) that it copies the null last, depending on whether you take
"after" to mean in the array or in time, but it's only an implication,
and an ambiguous one at that.

					der Mouse

			uucp: mouse@mcgill-vision.uucp
			arpa: mouse@larry.mcrcim.mcgill.edu

peter@athena.mit.edu (Peter J Desnoyers) (04/08/88)

--
If strcpy is not constrained to copying characters only up to the
terminating null, then it is free to copy any characters after this
point. Hence I could write a conforming strcpy which would, in a
hardware-dependent manner, either erase my program or cause a write
protection error. (I know this isn't that hot an idea.)

The source of the confusion  seems to be this: 
 There are two orderings being referred to in this discussion.
Characters in memory are ordered by address, and characters are copied
in some chronological order. 

For the definition of strcpy to make sense, it must define the address
range to be modified in terms of the arguments, and thus refer to
ordering in memory space. It may be a nicety, but is not absolutely
necessary, for the definition to refer to ordering in time, as this
does not change the functionality for non-overlapping strings. 


				Peter Desnoyers
				peter@athena.mit.edu

[man strcpy gives me: "strcpy copies string s2 to s1, stopping after
the null character has been moved." This seems to refer to order in
time, and not explicitly refer to the memory range modified. I don't
think it is a very rigorous definition.]