For functions registered using atexit(): Is it possible to retrieve references to them, to call them directly?

Although this is meant as a general question, solutions regarding the use of gcc/glibc are welcome.

有帮助吗?

解决方案

Not in any portable way, no. The list of registered functions is owned by the runtime library, and there is no interface to access it.

For glibc specifics as per your comment, the exit handlers are implemented by exit.c and exit.h. I haven't studied them intensely enough to figure out of it's possible to drill through the abstraction/data hiding. You might need to e.g. include glibc-specific headers that probably aren't generally available, for instance.

其他提示

No. However, if you have control over all the code in the application, you could maintain a list yourself, and register a single function to the real atexit() which would run through the list when the system is terminated.

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