Why typecast to void when call a function with no return value

Discussion in 'C Programming' started by su, Jan 23, 2009.

  1. su

    su Guest

    I found in old code that when calling a void function:

    foo() {
    (void) foo();

    I wonder why (void) is used to typecast the function.
    Is there any historical reason?

    Any reply from you will be appreciated.
    su, Jan 23, 2009
    1. Advertisements

  2. su

    Ian Collins Guest

    "cast", actors get "typecast" :)

    The reason is usually to suppress compiler or lint warnings, but they
    tend not to be a problem with functions returning void.
    Ian Collins, Jan 23, 2009
    1. Advertisements

  3. su

    su Guest

    Thanks. I got it.

    su, Jan 23, 2009
  4. su

    CBFalconer Guest

    And the number of scanfs and similar calls one sees unchecked
    indicate that insistance on the void usage might be helpful.
    CBFalconer, Jan 23, 2009
    1. Advertisements

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 (here). After that, you can post your question and our members will help you out.