473,890 Members | 2,014 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 6037
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*****@clawsh rimp.com> wrote in message
news:YI******** ************@ne ws02.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*****@clawsh rimp.com> wrote in message
news:YI******* *************@n ews02.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
2846
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"; std::system("PAUSE"); I've looked up "exit", "atexit" and "abort". Up until this point I simply would've done:
2
8837
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 { public: Book()
2
2084
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 exit(EXIT_FAILURE) and a different set of routines on exit(EXIT_SUCCESS). Any way of doing this?
7
6094
by: David Rushby | last post by:
Consider the following program (underscores are used to force indentation): ------------------------------------------------ import atexit, threading, time def atExitFunc(): ____print 'atExitFunc called.' atexit.register(atExitFunc)
5
1898
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 problem with the use of atexit.register as a decorator (and I can't think of any use case where this change would break any code). I describe the problem in the following text.
1
1983
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 atexit registered functions. ( Mainly static object destructors ) What I would like to achieve is have my custom atexit that calls the standard atexit. But when dlls are being unloaded and VS2005 is processing registered atexit functions, I...
20
6038
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 members / singletons (especially meyer type singletons) which use locally declared static variables. These variables are normally cleaned up automatically at shutdown of the application by registering with the atexit. I break point the destructor on...
16
3623
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 in the norm against this, I mean an as-if rule saying "atexit registered functions are executed as-if they were called from main", making val out of scope at this point. a+, ld. #include <stdio.h>
2
4769
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 source below. I understand the problem, but not how a preprocessor directive will fix it. He says the standard is unclear about the situation
0
10819
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10923
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10462
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9633
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
7169
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5851
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
6045
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4676
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
4271
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.