L
Laurent Deniau
I would like to know if the use of the pointer ref in the function
cleanup() below is valid or if something in the norm prevents this
kind of cross-reference during exit(). I haven't seen anything in the
norm against this, I mean an as-if rule saying "atexit registered
functions are executed as-if they were called from main", making val
out of scope at this point.
a+, ld.
#include <stdio.h>
#include <stdlib.h>
int *ref;
void cleanup(void) {
if (ref) fprintf(stderr, "val = %d\n", *ref);
}
void test(void) {
int val = 12;
ref = &val;
exit(EXIT_FAILURE);
}
int main(void) {
atexit(cleanup);
test();
return 0;
}
cleanup() below is valid or if something in the norm prevents this
kind of cross-reference during exit(). I haven't seen anything in the
norm against this, I mean an as-if rule saying "atexit registered
functions are executed as-if they were called from main", making val
out of scope at this point.
a+, ld.
#include <stdio.h>
#include <stdlib.h>
int *ref;
void cleanup(void) {
if (ref) fprintf(stderr, "val = %d\n", *ref);
}
void test(void) {
int val = 12;
ref = &val;
exit(EXIT_FAILURE);
}
int main(void) {
atexit(cleanup);
test();
return 0;
}