What is the strict aliasing rule in C++ and how does it break code?
Hello everyone. I've been writing in C++ for about a year, and recently I encountered a strange problem. I have a function that takes two pointers of different types, and I expect it to change the value through one pointer and then read it through another. Here's a simplified example:\n\n```cpp\n#include \n\nvoid foo(int* a, float* b) {\n *a = 42;\n *b = 3.14f;\n std::cout << *a; // expecting 42, but getting 0 or garbage\n}\n\nint main() {\n int x = 10;\n // I'm casting to interpret int memory as float\n foo(&x, reinterpret_cast(&x));\n return 0;\n}\n```\n\nI expect that after writing `*a = 42` and `*b = 3.14f`, the value of `*a` should be 42, but something strange is printed. The compiler (GCC with -O2) behaves as if my write to `*b` doesn't affect `*a` at all. I've heard