When not to use "strcpy".

Daniel J. Salomon djsalomon at watdaisy.UUCP
Mon Mar 18 10:24:29 AEST 1985


> Unfortunately, the string copy routines in the standard library are
> neither safe nor convenient.  strcpy is only usable if you KNOW that
> overrunning is impossible. ...
> ... My solution is to use my own string routines, which always take the
> maximum length of the destination string as a parameter.
> 
> _Greg Davidson (Virtual Infinity Systems, San Diego)

To all those who have been complaining about the flood of postings
relating to the string copy idiom, Greg Davidson's letter gives an
example of the type application in which it is important to know the
efficiencie of the string copy idiom versus other string copying
methods.
1) When one is writing low level, portable string handling routines
   and strcpy is not quite what you wanted.
2) When one is doing some other type of string scanning not supplied
   in the standard library.
The point that I wanted to make is that shorter source code does
not necessarily generate less object code.



More information about the Comp.lang.c mailing list