Atexit () bionic vs glibc function

I found an interesting point: 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 are the results different?

+4
source share
2 answers

It is not indicated whether the call to the atexit function, which is not executed before the call to the exit function, will succeed.

ISO C standard, Β§7.22.4.2. Thus, both behaviors are compatible; you cannot reliably register a function with atexit , and exit already uses atexit handlers.

+3
source

This behavior is unspecified. You can define several functions that will be called using atexit() several times, but you should not use it as soon as you exit the program (i.e., after you left main() ).

+1
source

All Articles