strcpy wars, jeez! A proposed resolution.
John Woods, Software
john at frog.UUCP
Sat Apr 2 08:46:00 AEST 1988
In article <3267 at haddock.ISC.COM>, karl at haddock.ISC.COM (Karl Heuer) writes:
>In article <4215 at ihlpf.ATT.COM> nevin1 at ihlpf.UUCP (00704a-Liber,N.J.) writes:
>>In article <6286 at dhw68k.cts.com> david at dhw68k.cts.com (David H. Wolfskill) writes:
>>>The current dpANS also specifies "If copying takes place between objects
>>>that overlap, the behavior is undefined." I would feel rather more
>>>comfortable with changing that to read "... implementation defined."
>>I would not! This would imply that a program which calls strcpy() with
>>overlapping strings is 'correct', and this is simply not true.
> But it would be true, if the standard were to explicitly allow it....if the
> "implementation-defined" part is properly phrased, strcpy(s,s+1) would be
> guaranteed to be safe.
Still no. The problem with "implementation-defined" is that there are no
constraints upon what the implementation may define the behavior to be.
If you port your program to an implementation where, in 3-point italic type
in a margin somewhere, they mention that strcpy(s,s+1) causes the CPU chip to
be launched upward with a velocity of 16 km/s, they will be _right._
>From the August 3, 1987 draft (and I assume this hasn't changed):
"1.7 COMPLIANCE
A _strictly conforming program_ shall use only those features of the
language and library specified in this standard. It shall not produce output
dependent on any unspecified, undefined, or ---> implementation-defined <---
behavior..." ( ---> Emphasis <--- added).
If you know that your implementation does what you want with strcpy(s,s+1),
then your are free to use it. Your program won't be "strictly conforming",
but you may not care about that. Just don't complain when you hear that
"chuffBANG!" of the CPU chip being launched when you buy that shiny new
Mark IV Datablaster...
--
John Woods, Charles River Data Systems, Framingham MA, (617) 626-1101
...!decvax!frog!john, ...!mit-eddie!jfw, jfw at eddie.mit.edu
FUN: THE FINAL FRONTIER
Zippy the Pinhead in '88!
More information about the Comp.lang.c
mailing list