How to quit void functions

Discussion in 'C Programming' started by Martin Johansen, Apr 30, 2004.

  1. Hello.

    I have a void function.

    Now, how do I exit the function at a random line in the code?

    Normally I would use the return statement.

    Thanks.
    Martin Johansen, Apr 30, 2004
    #1
    1. Advertising

  2. Martin Johansen wrote:

    > Hello.
    >
    > I have a void function.
    >
    > Now, how do I exit the function at a random line in the code?
    >
    > Normally I would use the return statement.


    To return from the function at any specified point use the return
    statement. Exiting randomly is not a good idea.
    Martin Ambuhl, Apr 30, 2004
    #2
    1. Advertising

  3. >I have a void function.
    >Now, how do I exit the function at a random line in the code?
    >
    >Normally I would use the return statement.


    Use the return statement.

    void logerror(char *msg)
    {
    if (msg == NULL) {
    return;
    }
    if (msg[0] == '\0') {
    return;
    }
    ... stuff to output the string pointed at by msg to a log file ...

    return; /* optional */
    }

    Gordon L. Burditt
    Gordon Burditt, Apr 30, 2004
    #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. Rahmi Acar
    Replies:
    5
    Views:
    421
    Karl Heinz Buchegger
    Jul 28, 2003
  2. Ollej Reemt
    Replies:
    7
    Views:
    518
    Jack Klein
    Apr 22, 2005
  3. Stig Brautaset

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

    Stig Brautaset, Oct 25, 2003, in forum: C Programming
    Replies:
    15
    Views:
    786
    The Real OS/2 Guy
    Oct 28, 2003
  4. Replies:
    5
    Views:
    824
    S.Tobias
    Jul 22, 2005
  5. Replies:
    1
    Views:
    401
    Victor Bazarov
    May 23, 2007
Loading...

Share This Page