Here i have very simple program:
#include <iostream>
int main()
{
while(1);
}
void unreal() {
std::cout << "Hello world!" << std::endl;
}
For some reason if unreal fucntion placed after main, compiled program prints "Hello word", despite the fact that unreal fucntion never called explicitly. Why does this happen? Is it just consequences of optimizations and undefined behavior caused by them?
Compiled with:
clang++17 loop.cpp -O1 -o loop
clang++-17 --version
Ubuntu clang version 17.0.0 (++20230510031624+e5532fb4935b-1~exp1~20230510151722.922)
Target: x86_64-pc-linux-gnu
Thread model: posix