Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > why cast memcpy's return value to void

Reply
Thread Tools

why cast memcpy's return value to void

 
 
murat.migdisoglu@gmail.com
Guest
Posts: n/a
 
      05-02-2006
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

 
Reply With Quote
 
 
 
 
Richard Heathfield
Guest
Posts: n/a
 
      05-02-2006
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)
 
Reply With Quote
 
 
 
 
Tomás
Guest
Posts: n/a
 
      05-02-2006
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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
findcontrol("PlaceHolderPrice") why why why why why why why why why why why Mr. SweatyFinger ASP .Net 2 12-02-2006 03:46 PM
CAN WE TYPE CAST AN INTEGER AS (VOID *)X..(Like can I return a value (void *)x) Abhishek C Programming 12 01-30-2006 03:22 PM
what is the difference, void func(void) and void fucn() noblesantosh@yahoo.com C Programming 5 07-22-2005 04:38 PM
"void Method()" vs "void Method(void)" Ollej Reemt C++ 7 04-22-2005 03:47 AM
`void **' revisited: void *pop(void **root) Stig Brautaset C Programming 15 10-28-2003 09:03 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57