[vox-tech] Where setjmp/longjmp went after C

Micah Cowan vox-tech@lists.lugod.org
16 Mar 2002 22:30:04 -0800


On Sat, 2002-03-16 at 13:25, Jeff Newmiller wrote:
> The attached two files demonstrate a rudimentary "structured
> setjmp/longjmp" that mimics the "exceptions" of Ada and C++ (and other
> languages).  I wrote an article about this in spring 1991 for C User's
> Journal, and my bad luck was that two other people beat me to the punch,
> so it never got published.  What I have here is pulled from memory, but I
> think it gets the idea across.
> 
> The real value of this technique comes into play when everyone uses the
> same system... and you need language support to avoid certain problems
> with auto variables... so I would only recommend using this if you are
> stuck in C. :)

The real problem with using setjmp()/longjmp() these days:  C99 has
added a very cool type, the variable length array.  Unfortunately, the
standard declares that calling longjmp() when the call stack includes
functions which have defined VLAs which still exist, they may not be
deallocated by the stack-unwinding. :(  So, you get memory leaks...

That sucks.  The one thing I really dislike about the new C.  Other than
that, it rocks.

Micah