...
Code Block | ||
---|---|---|
| ||
#include <stdio.h>
#include <stdlib.h>
void exit1(void) {
if(expr)
exit();
//clean up and ready program for closing
...
}
int main (void) {
atexit(exit1);
...
//program code
exit();
return 0;
}
|
Compliant Code
...
Code Block | ||
---|---|---|
| ||
#include <stdio.h> #include <stdlib.h> #include <stdio.h> #include <stdlib.h> void exit1(void) { if(expr) _Exit(); //clean up and ready program for closing ... } int main (void) { atexit(exit1); ... //program code exit(); return 0; } |
The call to _Exit() will immediately terminate the program and no undefined behavior will happen like in the non compliant example.
...