Are all functions in C/C++ assumed to return?

后端 未结 7 1490
抹茶落季
抹茶落季 2020-12-31 01:49

I was reading this paper on undefined behaviour and one of the example \"optimisations\" looks highly dubious:

if (arg2 == 0)
    ereport(ERROR,         


        
7条回答
  •  感情败类
    2020-12-31 02:28

    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.

提交回复
热议问题