The code in this post is an example from CppCon2023 - Fedor Pikus s talk on UB. Unfortunately, the speaker does not explain this specific behavior in their talk - this knowledge is presumed to be common among the attendees, but I am sadly missing it...
The following Code, prepared with -O3 using both Corng or gcc (various texts Trial in Compiler Exploration), shows different conduct if int i
is global vs local to
是全球性的,那么空洞就消失了,但如果是地方性的的话。main
。 具体来说,如果<代码>t i
#include <iostream>
int i = 1;
int main() {
std::cout << "Before infinite loop" << std::endl;
while (i) {}
std::cout << "After infinite loop.... wat?" << std::endl;
}
我以上述话题和在StackOverflow上的类似问题为基础,理解空档为UB,可以由汇编者去除;我不理解(而且不能发现任何关于这一主题的信息) 。
在界定了<代码>int i的情况下,为何如此?