468,512 Members | 1,422 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,512 developers. It's quick & easy.

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?
Mar 18 '08 #1
1 5926
weaknessforcats
9,207 Expert Mod 8TB
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.
Mar 19 '08 #2

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

16 posts views Thread by Delali Dzirasa | last post: by
2 posts views Thread by Gernot Frisch | last post: by
3 posts views Thread by cylin | last post: by
6 posts views Thread by myhotline | last post: by
70 posts views Thread by Rajan | last post: by
1 post views Thread by remove the CAPS | last post: by
39 posts views Thread by Martin Jørgensen | last post: by
2 posts views Thread by murat.migdisoglu | last post: by
1 post views Thread by fmendoza | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.