Domanda

is it possible to unregister an exit handler function???

void exit_handler_1()
{
    printf("in first exit handler\n");
}

int main()
{
    if(atexit(exit_handler_1())
    {
        perror("error");
    }
    return 0;
}
È stato utile?

Soluzione

It is not possible.

Why not just register one atexit function and have a global variable for that function to be able to decide what is required of it.

Altri suggerimenti

You can't unregister atexit functions, but you can disable your own functions.

static int disable_my_exit_handler = 0;

void exit_handler_1()
{
    if ( disable_my_exit_handler )
        return;

    printf("in first exit handler\n");
}

int main( void )
{
    if ( atexit( exit_handler_1 ) )
    {
        perror("error");
    }

    disable_my_exit_handler = 1;
    return 0;
}

atexit allows a function to be registered multiple times too. In order to unregister a function, the non-existing unregister_atexit has to allow not only the function but also the position from which you want to unregister it. This quickly leads to exposing the interface of the stack used to keep store the functions registered by atexit.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top