setjmp, longjmp

Discussion in 'C Programming' started by Mantorok Redgormor, Nov 12, 2003.

  1. is there a portable way of implementing exception handling with setjmp, longjmp?

    restoring the state of a program and such really seems like I am asking
    for undefined behavior.

    --
    nethlek
     
    Mantorok Redgormor, Nov 12, 2003
    #1
    1. Advertising

  2. Mantorok Redgormor

    Derk Gwen Guest

    (Mantorok Redgormor) wrote:
    # is there a portable way of implementing exception handling with setjmp, longjmp?
    #
    # restoring the state of a program and such really seems like I am asking
    # for undefined behavior.

    It's the only standard way to exit a nest of called functions to a
    particular point in a calling ancestor. You should not expect to restore
    local or global variables--if you need that behaviour, store the originals
    elsewhere and copy back at the setjmp. You should not expect not to
    restore non-volatile variables--if you need that, declare them volatile.

    --
    Derk Gwen http://derkgwen.250free.com/html/index.html
    Haven't you ever heard the customer is always right?
     
    Derk Gwen, Nov 12, 2003
    #2
    1. Advertising

  3. Mantorok Redgormor

    Ian Woods Guest

    (Mantorok Redgormor) wrote in
    news::

    > is there a portable way of implementing exception handling with
    > setjmp, longjmp?
    >
    > restoring the state of a program and such really seems like I am
    > asking for undefined behavior.
    >
    > --
    > nethlek


    The only state of the program which is not preserved by longjmping are
    automatic variables IIRC. I wrote a toy exception handling 'thing' a long
    time ago in here which exploited that fact. You had to specifically
    preserve the automatic variables you wanted to keep (and you could keep
    them at stages in the 'try' block), but it was all very much a hack.

    I'll try and have a dig around and see if I still have it. If not, I might
    just rewrite it for laughs.

    Ian Woods
     
    Ian Woods, Nov 12, 2003
    #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. Thomas Baruchel

    How dirty is setjmp+fopen+longjmp ?

    Thomas Baruchel, Oct 2, 2003, in forum: C Programming
    Replies:
    2
    Views:
    458
    Eric Sosman
    Oct 2, 2003
  2. someone
    Replies:
    5
    Views:
    3,469
    SM Ryan
    May 1, 2004
  3. Michael B Allen

    Is setjmp/longjmp ok?

    Michael B Allen, May 1, 2004, in forum: C Programming
    Replies:
    11
    Views:
    2,259
    -wombat-
    May 4, 2004
  4. Ravi Uday

    setjmp/longjmp

    Ravi Uday, Aug 3, 2004, in forum: C Programming
    Replies:
    2
    Views:
    549
    Dave Vandervies
    Aug 6, 2004
  5. Jrferguson

    A bit off topic; setjmp/longjmp

    Jrferguson, Oct 29, 2004, in forum: C Programming
    Replies:
    4
    Views:
    495
    Dan Pop
    Nov 2, 2004
Loading...

Share This Page