473,395 Members | 1,504 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

atexit()

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?

Cheers

Steve
Nov 14 '05 #1
2 2053

"Steve Lambert" <st***********@ntlworld.com> wrote in message
news:Tm***************@newsfe1-gui.ntli.net...
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?


My first thought was to pass this info ('failure' or 'success')
via an argument to the registered function. BUT:

==========================================
From the C standard:

7.20.4.2 The atexit function

Synopsis

1 #include <stdlib.h>
int atexit(void (*func)(void));

Description

2 The atexit function registers the function pointed to by func,
to be called without arguments at normal program termination.

Environmental limits

3 The implementation shall support the registration of at least
32 functions.

Returns

4 The atexit function returns zero if the registration succeeds,
nonzero if it fails.

==========================================
So, as much as I dislike using globals, it seems that would
be the way to pass this info: set a global to EXIT_SUCCESS
or EXIT_FAILURE (or whatever other value you find useful),
and have a 'controlling' registered function inspect that
value, and invoke one of a set of other functions which
performs the desired actions.

-Mike
Nov 14 '05 #2
Groovy hepcat Mike Wahler was jivin' on Thu, 30 Sep 2004 23:21:34 GMT
in comp.lang.c.
Re: atexit()'s a cool scene! Dig it!
"Steve Lambert" <st***********@ntlworld.com> wrote in message
news:Tm***************@newsfe1-gui.ntli.net...

Is it possible for the functions registered with atexit() to have accessto
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?


[Snip.]
So, as much as I dislike using globals, it seems that would
be the way to pass this info: set a global to EXIT_SUCCESS
or EXIT_FAILURE (or whatever other value you find useful),
and have a 'controlling' registered function inspect that
value, and invoke one of a set of other functions which
performs the desired actions.


That's what I would have suggested if you hadn't beaten me to it. :)
But I would add this.
Make the so called global variable static and put it in its own
translation unit. Also put in this translation unit an exit() wrapper
that sets this variable and a function to read its value. When exiting
the program, call the wrapper instead of exit() directly, and call
the other function from the function registered with atexit().

--

Dig the even newer still, yet more improved, sig!

http://alphalink.com.au/~phaywood/
"Ain't I'm a dog?" - Ronny Self, Ain't I'm a Dog, written by G. Sherry & W. Walker.
I know it's not "technically correct" English; but since when was rock & roll "technically correct"?
Nov 14 '05 #3

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

Similar topics

3
by: Serve Laurijssen | last post by:
Does the C++ standard say whether destructors are called before or after "atexit" functions are called. Or is nothing said about that?
8
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";...
7
by: David Rushby | last post by:
Consider the following program (underscores are used to force indentation): ------------------------------------------------ import atexit, threading, time def atExitFunc(): ____print...
5
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
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
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
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
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...
18
by: lak | last post by:
I am studying the Advanced programming in the unix environment. There they says that we can register upto 32 functions with atexit(). Why that is limited to 32 functions? can any one tell the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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
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...
0
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
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...

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.