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?

有帮助吗?

解决方案

It is unspecified whether a call to the atexit function that does not happen before the exit 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.

其他提示

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()).

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top