In early versions of the C language, every function would return something, whether or not the caller would make use of the returned value. Generally, the return value of a function would be whatever happened to be in some particular register of the appropriate type. If code exited a function without making any effort to set the register to something meaningful, and calling code ignored the contents of the register in question, having the function nominally return a meaningless value was simpler and easier than providing a means of having functions not return a value.
I don't think any particular thought was put into the question of what functions like memcpy
, strcpy
, or strcat
should return, but the authors of the Standard didn't want to simply leave the return value unspecified. Since there may have been platforms where functions that don't return a value would be processed differently from those that do, giving such functions a void
return type could have broken code that calls the functions without including the appropriate standard header.
I don't think any particular effort was made to have the functions return the most useful value. More likely, the authors of the Standard wanted to have the functions return some specified value, and so they somewhat arbitrarily picked a value to be returned.
strcpy
) etc. That just changes the question to “… the rationale for havingstrcpy
return one of its inputs?”void strcpy(char *s, char *t)
(no return value) and then just says “Thestrcpy
in the standard library (<string.h>
) returns the target string as its function value.”errno
anderrno.h
can be found here: archive.org/details/cprogramming0000koch/page/47/mode/1up