memcpy return value

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • manu1001
    New Member
    • Jul 2007
    • 14

    #1

    memcpy return value

    Why does memcpy(void *t, const void *s, size_t c) return t?
    I've seen quite a few functions that return an argument. Any particular reason to do so? Any disadvantage if the function did not return anything?
  • weaknessforcats
    Recognized Expert Expert
    • Mar 2007
    • 9214

    #2
    A return value is used a) so the function call can appear on the right side of an assignment operator as an RVAL, b) so the function can report an error.

    The real trick is to avoid using the return type for both purposes at once. Like, if it returns a value >= zero it's OK but a returning a value < 0 is an error code.

    Too often the user will call the function, failt to test the return, get a value <0 and proceed into the program using the error code as a result.

    In C++ only case (a) is needed, that is to use the function as an RVAL. Case (b) is handled by using exceptions.

    Comment

    Working...