home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c++
- Path: sparky!uunet!stanford.edu!lucid.com!lucid.com!jss
- From: jss@lucid.com (Jerry Schwarz)
- Subject: Re: setjmp/longjmp question
- Message-ID: <1993Jan27.045937.10463@lucid.com>
- Sender: usenet@lucid.com
- Reply-To: jss@lucid.com (Jerry Schwarz)
- Organization: Lucid, Inc.
- References: <1993Jan8.195613.14303@cadkey.com> <KANZE.93Jan25184636@slsvdnt.us-es.sel.de>
- Date: Wed, 27 Jan 93 04:59:37 GMT
- Lines: 56
-
- In article <KANZE.93Jan25184636@slsvdnt.us-es.sel.de>, kanze@us-es.sel.de (James Kanze) writes:
-
- |>
- |> The C++ standards committee have said that they are adopting the C
- |> library more or less integrally, so I would suppose that this means
- |> setjmp/longjmp too.
-
- The committee decided to include setjmp/longjmp, but with the
- proviso
-
- "If any automatic objects would have been destroyed as a
- result of an exception passing control to the same function
- as the longjmp, the results of the longjmp are undefined."
-
- In effect, this means that longjmp is present and will work the
- way it does in C provided all your code stays in the C subset.
- In code using constructors and destructors (what some people
- might call "real C++") you shouldn't use it. Note it isn't
- just that the destructors may or may not be called, but the
- exception handling mechanism itself might be corrupted by
- use of longjmp.
-
- I believe there were three points of view expressed during
- the discussions leading up to this decision.
-
- A) Not include them in the standard library. Vendors would be
- free to continue to support them in any way they chose.
-
- The objection to this was that it might severely
- impact people trying to turn C code into C++.
-
- B) Include them and "fix them" to call the destructors (the
- way exceptions would).
-
- The objection to this is that a lot of C++ code already
- exists that uses longjmp/setjmp and doesn't expect the
- destructors to be called. This alternative might
- severely impact such code. And it would
- make it difficult to write code that works both
- with today's systems and future systems that implement
- this rule.
-
- C) Include them and say they don't call destructors.
-
- The objection to this is that the standard shouldn't contain
- a mechanism for subverting the usual guarantee that destructors
- are called when stack variables are deallocated.
-
- I believe this will work out reasonably well. People can continue
- to use setjmp/longjmp. As vendors phase in exception handling
- they ought to continue to support existing use of setjmp/longjmp
- As systems without exceptions fade away programmers should discontinue
- using setjmp/lonjmp. (Although I personally think the transition
- period will be measured in decades.)
-
- -- Jerry Schwarz
-