why cast memcpy's return value to void

  • Thread starter murat.migdisoglu
  • Start date
M

murat.migdisoglu

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
 
R

Richard Heathfield

(e-mail address removed) 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).
 
T

Tomás

(e-mail address removed) 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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top