Reputation: 6960
I found interesting moment: the atexit()
function works differently for bionic
and glibc
. Here is an example:
#include <cstdlib>
#include <cstdio>
extern "C" {
void one(){
printf("one\n");
}
void two() {
printf("two\n");
atexit(one);
}
}
int main() {
atexit(two);
}
Results for bionic
:
two
Results for glibc
:
two
one
Why do the results differ?
Upvotes: 4
Views: 554
Reputation: 363797
It is unspecified whether a call to the
atexit
function that does not happen before theexit
function is called will succeed.
ISO C standard, §7.22.4.2. So both behaviors are compliant; you can't reliably register a function using atexit
while exit
is already running its atexit
handlers.
Upvotes: 3
Reputation: 36537
This behavior is unspecified. You can define multiple functions to be called using atexit()
multiple times, but you must not use it once you're already exiting the program (i.e. once you've left main()
).
Upvotes: 1