Hi!
I know that it will be obvious for real C++-masters, but for me it is small surprise. I used to think that signed overflow in C ++ does not cause real undefined behavior on a particular platform. That is, it is clear that depending on the big-endianness/little-endian result may be different.
I found short and funny example:
#include <iostream>
int main()
{
for (int i = 0; i < 300; i++)
std::cout << i << " " << i * 12345678 << std::endl;
}
Being compiled with -O2
on modern g++ it will run infinitely.
Этот код при компиляции с -O2
в современном g++ приводит к бесконечному циклу. Suddenly, right?