471,084 Members | 962 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,084 software developers and data experts.

why cast memcpy's return value to void

hi,
while i was browsing some codes, i've seen multiple times casting the
return value of memcpy function to void.
(
......;
......;
(void)memcpy(.......);
.....;
)

is there any particular reason for that?

thanks for your attention

May 2 '06 #1
2 4168
mu**************@gmail.com said:
hi,
while i was browsing some codes, i've seen multiple times casting the
return value of memcpy function to void.
(
.....;
.....;
(void)memcpy(.......);
....;
)

is there any particular reason for that?


Three possible reasons spring to mind:

(1) it might shut lint up. Depending on which lint you've got.
(2) it might be mandated by some stupid in-house coding style thing.
(3) some people just love to type.
There is no technical merit in it whatsoever, but it doesn't do any harm
either (except to the eyes).
--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at above domain (but drop the www, obviously)
May 2 '06 #2
mu**************@gmail.com posted:
hi,
while i was browsing some codes, i've seen multiple times casting the
return value of memcpy function to void.
(
.....;
.....;
(void)memcpy(.......);
....;
)

is there any particular reason for that?

thanks for your attention

As Richard said, some compilers give hyper-warnings if you discard a
function call's return value. For instance:

int Func(void) { return 6; }

int main()
{
Func();
}

WARNING: Return value of call to "Func()" discarded.
-Tomás
May 2 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

28 posts views Thread by christopher diggins | last post: by
16 posts views Thread by Amarendra GODBOLE | last post: by
15 posts views Thread by Michael Baehr | last post: by
9 posts views Thread by gvarndell | last post: by
7 posts views Thread by James Mcguire | last post: by
70 posts views Thread by Rajan | last post: by
1 post views Thread by remove the CAPS | last post: by
6 posts views Thread by Jack | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.