why cast memcpy's return value to void

Discussion in 'C Programming' started by murat.migdisoglu@gmail.com, May 2, 2006.

  1. Guest

    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, 2006
    #1
    1. Advertising

  2. 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)
    Richard Heathfield, May 2, 2006
    #2
    1. Advertising

  3. Tomás Guest

    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
    Tomás, May 2, 2006
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Ollej Reemt
    Replies:
    7
    Views:
    498
    Jack Klein
    Apr 22, 2005
  2. Stig Brautaset

    `void **' revisited: void *pop(void **root)

    Stig Brautaset, Oct 25, 2003, in forum: C Programming
    Replies:
    15
    Views:
    773
    The Real OS/2 Guy
    Oct 28, 2003
  3. Mr. SweatyFinger
    Replies:
    2
    Views:
    1,733
    Smokey Grindel
    Dec 2, 2006
  4. Replies:
    5
    Views:
    814
    S.Tobias
    Jul 22, 2005
  5. Abhishek
    Replies:
    12
    Views:
    787
    Eric Sosman
    Jan 30, 2006
Loading...

Share This Page