I was reading this paper on undefined behaviour and one of the example \"optimisations\" looks highly dubious:
if (arg2 == 0) ereport(ERROR,
It seems to me that unless the compiler can prove that ereport()
doesn't call exit()
or abort()
or some other mechanism for program termination then this optimization is invalid. The language standard mentions several mechanisms for termination, and even defines the 'normal' program termination via returning from main()
in terms of the exit()
function.
Not to mention that program termination isn't necessary to avoid the division expression. for (;;) {}
is perfectly valid C.