473,503 Members | 1,629 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

atexit and global destructors

Does the C++ standard say whether destructors are called before or after
"atexit" functions are called.
Or is nothing said about that?

Jul 22 '05 #1
3 5986
Serve Laurijssen wrote:
Does the C++ standard say whether destructors are called before or after
"atexit" functions are called.
Or is nothing said about that?


3.6.3/3 says
"If a function is registered with atexit then following the
call to exit, any objects with static storage duration initialized
prior to the registration of that function shall not be
destroyed until the registered function is called from the
termination process and has completed.
For an object with static storage duration constructed after a
function is registered with atexit, then following the call to
to exit, the registered function is not called until the execution
of the object's destructor has completed.
If atexit is called during the construction of an object, the
complete object to which it belongs shall be destroyed
before the registered function is called."

Jacques.

Jul 22 '05 #2

"Jacques Labuschagne" <ja*****@clawshrimp.com> wrote in message
news:YI********************@news02.tsnz.net...
3.6.3/3 says
"If a function is registered with atexit then following the
call to exit, any objects with static storage duration initialized
prior to the registration of that function shall not be
destroyed until the registered function is called from the
termination process and has completed.


So if I understand correctly,
when I call atexit at the first line in main, all global static objects will
be destroyed after the registered function is executed?
Jul 22 '05 #3
On Thu, 15 Jan 2004 11:57:30 +0100, "Serve Laurijssen"
<cs@nospam.comp.com> wrote:

"Jacques Labuschagne" <ja*****@clawshrimp.com> wrote in message
news:YI********************@news02.tsnz.net...
3.6.3/3 says
"If a function is registered with atexit then following the
call to exit, any objects with static storage duration initialized
prior to the registration of that function shall not be
destroyed until the registered function is called from the
termination process and has completed.


So if I understand correctly,
when I call atexit at the first line in main, all global static objects will
be destroyed after the registered function is executed?


No, since not all global static objects are guaranteed to have been
initialized before the first line of main (although they will on most
platforms when not using dynamic loading). The standard allows global
statics in to remain uninitialized until you use the translation unit
that the static is initialized in, to facilitate dynamic loading of
modules.

Tom

C++ FAQ: http://www.parashift.com/c++-faq-lite/
C FAQ: http://www.eskimo.com/~scs/C-faq/top.html
Jul 22 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
2819
by: JKop | last post by:
Let's say that when your program ends (no matter how) that you want a certain block of code to be executed at the end. Here's the code: std::cout << "The program will now end.\n";...
2
8800
by: Thomas Matthews | last post by:
Hi, I'm getting linking errors when I declare a variable in the global scope, but not inside a function. The declarations are the same (only the names have been changed...). class Book {...
2
2060
by: Steve Lambert | last post by:
Hi, Is it possible for the functions registered with atexit() to have access to parameter to exit i.e EXIT_SUCCESS or EXIT_FAILURE? I'd like to register a set of routines to be executed on...
7
6055
by: David Rushby | last post by:
Consider the following program (underscores are used to force indentation): ------------------------------------------------ import atexit, threading, time def atExitFunc(): ____print...
5
1881
by: prouleau001 | last post by:
Hi all! Since that the decorator syntax is upon us, I think it would be good if atexit.register() was returning the function passed as argument. This simple change to the library would solve a...
1
1963
by: Parapura Rajkumar | last post by:
hey all I was wondering if there a way to override atexit in my own module. The problem I was facing is that the VS2005 seems to ignore functions registered with atexit once it starts processing...
20
5971
by: Aek | last post by:
We recently moved our large codebase over from VS7 to 8 and found that we now get access violations in atexit calls at shutdown when debugging the application in VS2005. This occurs in static...
16
3571
by: Laurent Deniau | last post by:
I would like to know if the use of the pointer ref in the function cleanup() below is valid or if something in the norm prevents this kind of cross-reference during exit(). I haven't seen anything...
2
4742
by: Christopher Pisz | last post by:
I am attempting to write a "Phoenix Singleton" using the book "Modern C++ Design" by Alexandrescu I do not understand his use of... #ifndef ATEXIT_FIXED std::atexit(Kill); #endif ....in the...
0
7198
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7072
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7319
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
6979
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
5570
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
3160
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3149
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
730
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
373
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.