This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: when do object destuctors run?
- To: Clint Laschkewitsch <clintl at us dot ibm dot com>
- Subject: Re: when do object destuctors run?
- From: Phil Edwards <pedwards at disaster dot jaj dot com>
- Date: Wed, 25 Jul 2001 19:43:58 -0400
- Cc: gcc at gcc dot gnu dot org
- References: <OFA9C75B03.66D09BA2-ON86256A86.00501116@rchland.ibm.com>
On Wed, Jul 11, 2001 at 09:38:38AM -0500, Clint Laschkewitsch wrote:
> I'm looking at writing some C++ application level code to run on top of
> Linux. It would be compiled with the GNU gcc compiler for a 405 PowerPC
> processor. Not sure, yet, which version of the compiler...2.95 or 3.0.
> If the version makes a difference, let me know.
3.0 is far more standards-compliant, but runs slower and can produce
slower code. This has already been addressed (and will continue to be
addressed) for 3.0.x and 3.1.
> Questions have come up about how good the compiler and Linux implemantation
> are in regard to running object destructors. That is, how robust is the
> combination of gcc and Linux in getting destructors run when an object goes
> out of scope.
The platform shouldn't have anything to do with it. And this is pretty
trivial for any compiler to get right.
> For example, I assume the simple cases of an object being created inside a
> code block and the end of the code block being reached or the return from
> main would run the destructors for objects within that scope.
>
> But what about more complex problems that cause a process to end? Such as
> someone doing a kill on some daemon process. Or some signal being sent to
> a process which causes the process to die. Will the object destructors get
> called in these cases?
No, because this is outside the scope of the language. The C++ standard
doesn't make any assumptions about what kind of environment its programs
are going to run in ("process? wot's that?") for the most part.
Mmmmm, there are a couple of points... the default action for a signal may
be to "terminate with a core dump," but whether that's done by calling
abort() is unspecified by POSIX, I believe. The C++ language /does/
specify that when abort() is called, destructors are /not/ called and
atexit()-registered functions are not run.
For the most part there is little to no specification from the language's
side about contingencies on the environment's side. This is getting really
off-topic for this list, so I'll stop here.
Phil
--
Would I had phrases that are not known, utterances that are strange, in
new language that has not been used, free from repetition, not an utterance
which has grown stale, which men of old have spoken.
- anonymous Egyptian scribe, c.1700 BC