🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

3 total messages Started by Alex Rezinsky Sun, 17 Dec 1995 13:59
setjmp/longjmp in C++
#859
Author: Alex Rezinsky
Date: Sun, 17 Dec 1995 13:59
9 lines
572 bytes
        Hi all,

Can I use setjmp/longjmp routines in C++ environment (g++ compiler)?
Do they save/restore C++ environment correctly?
Does longjmp call default destructors?

Thanks,
Alex
Re: setjmp/longjmp in C++
#858
Author: Mike Rubenstein
Date: Sun, 17 Dec 1995 17:17
29 lines
1456 bytes
alexr@msil.sps.mot.COM (Alex Rezinsky) wrote:

|>
|>        Hi all,
|>
|>Can I use setjmp/longjmp routines in C++ environment (g++ compiler)?
|>Do they save/restore C++ environment correctly?
|>Does longjmp call default destructors?

In theory you can use setjmp/longjmp, in C++, but they are very
restricted.  From the September draft 18.7:

	The function signature longjmp(jmp_buf jbuf, int val) has more
	restricted behavior in this International Standard.  If any 
	automatic objects  would be destroyed by a thrown exception
	transferring control to another  (destination)  point  in  the

	program, then a call to longjmp(jbuf, val) at the throw point
	that transfers control to the same (destination) point has
	undefined behavior.

In practice, this is so restrictive that I would say that these macros
are not usable in C++.  Use exceptions instead.

I expect that most compilers will not destroy auto objects when
longjmp() is called unless they actually implement setjmp/longjmp with
exceptions.

Michael M Rubenstein
Re: setjmp/longjmp in C++
#861
Author: 7114075
Date: Mon, 18 Dec 1995 18:04
17 lines
1068 bytes
In <9512171357.AA03464@msil.sps.mot.com>, alexr@msil.sps.mot.COM (Alex Rezinsky) writes:
>
>        Hi all,
>
>Can I use setjmp/longjmp routines in C++ environment (g++ compiler)?
>Do they save/restore C++ environment correctly?
>Does longjmp call default destructors?
>
>Thanks,
>Alex

Alex;
	Yes, you can use setjmp/longjmp. No, you shouldn't. They do not
call destructors, and in fact, unless used very carefully, are almost
guaranteed to mess up memory. Exception handling will address these
problems, but I don't know of any compilers currently implementing
exception handling according to the standard.
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads