I can pass regular function pointer to atexit():
void f1(void)
{
printf("f1\n");
}
int main() {
void (*fun_ptr)(void) = &f1;
atexit(fun_ptr);
}
But when I pass function pointer returned from another function:
typedef void (*f22_t) (void);
f22_t f2(void) {
void f22(void) {
printf("f22\n");
}
return f22;
}
int main() {
void (*fun_ptr2)(void) = f2();
atexit(fun_ptr2);
}
It results in:
Illegal instruction (core dumped)
Why does the first option wors and second one does not?
Also, I might be misreading the documentation on atexit()
https://man7.org/linux/man-pages/man3/atexit.3.html
or
https://pubs.opengroup.org/onlinepubs/007904875/functions/atexit.html
but it does not look to me anything there mentions the information why the second scenario would not work.