Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

The method for providing arguments to a function within atexit() in C is to create a separate function that takes no arguments, but instead calls the desired function with the required arguments. This way, the argument values are preserved and can be passed to the desired function when atexit() is called.

For example, if you have a function called myFunction(int arg1, float arg2), you can create a separate function called myFunctionWrapper() that takes no arguments, but calls myFunction() with the desired values:

void myFunctionWrapper() {
    int arg1 = 5;
    float arg2 = 3.14;
    myFunction(arg1, arg2);
}

int main() {
    atexit(myFunctionWrapper);
    // other code...
}

When the program terminates, myFunctionWrapper() will be called, which will in turn call myFunction() with the correct argument values.