best way to do this: on error goto beginning of the main()?

Discussion in 'C Programming' started by John Smith, Sep 24, 2005.

  1. John Smith

    John Smith Guest

    I want the program to jump to the beginning of the main() if in a
    function a certain error is detected. What's the best way to
    handle this?
     
    John Smith, Sep 24, 2005
    #1
    1. Advertising

  2. John Smith

    SM Ryan Guest

    John Smith <> wrote:
    # I want the program to jump to the beginning of the main() if in a
    # function a certain error is detected. What's the best way to
    # handle this?
    #
    #

    setjmp/longjmp perhaps.

    --
    SM Ryan http://www.rawbw.com/~wyrmwif/
    She broke your heart and inadvertently drove men to deviant lifestyles.
     
    SM Ryan, Sep 24, 2005
    #2
    1. Advertising

  3. John Smith

    Mike Wahler Guest

    "John Smith" <> wrote in message
    news:e0hZe.72295$...
    >I want the program to jump to the beginning of the main() if in a
    > function a certain error is detected. What's the best way to
    > handle this?


    "Best" is a subjective term. But consider:

    #include <stdio.h>

    int func(int arg)
    {
    if(arg < 0)
    return 0;
    else
    return 1;
    }

    int main()
    {
    int i = -2;

    /* 'beginning of main()' */
    while(!func(i))
    printf("func(): invalid argument (%d)\n", i++);

    printf("func(): argument (%d) OK\n", i);
    return 0;
    }

    -Mike
     
    Mike Wahler, Sep 24, 2005
    #3
  4. SM Ryan wrote on 24/09/05 :
    > John Smith <> wrote:
    > # I want the program to jump to the beginning of the main() if in a
    > # function a certain error is detected. What's the best way to
    > # handle this?
    > #
    > #
    >
    > setjmp/longjmp perhaps.


    The OP asked for the best, not the worst...

    --
    Emmanuel
    The C-FAQ: http://www.eskimo.com/~scs/C-faq/faq.html
    The C-library: http://www.dinkumware.com/refxc.html

    "Clearly your code does not meet the original spec."
    "You are sentenced to 30 lashes with a wet noodle."
    -- Jerry Coffin in a.l.c.c++
     
    Emmanuel Delahaye, Sep 24, 2005
    #4
    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. John M
    Replies:
    1
    Views:
    1,292
    Kumar Reddi
    May 29, 2005
  2. wenjie wang
    Replies:
    5
    Views:
    494
    wenjie wang
    Nov 1, 2004
  3. Hal Styli
    Replies:
    14
    Views:
    1,709
    Old Wolf
    Jan 20, 2004
  4. Laurent
    Replies:
    20
    Views:
    499
    Chris Angelico
    Sep 9, 2011
  5. Jesse B.
    Replies:
    9
    Views:
    260
    Jesse B.
    Mar 27, 2010
Loading...

Share This Page