Search code examples
catexit

change atexit behavior based on program status


I am trying register one function with atexit () that will print different messages based off of the current status of the program. I know that when you register the function with atexit you cannot pass an argument.

So, how can you pass the program status, say an integer, and make that function print different statements?

I know that I can register multiple functions, but I have to only use one.


Solution

  • Use a global variable. That can be read by your function registered with atexit.