| ▲ | masklinn 10 hours ago | |||||||||||||||||||||||||
The compiler is the arbiter of what’s what (as long as it does not run afoul the CPU itself). The memory being uninitialised means reading it is illegal for the writer of the program. The compiler can write to it if that suits it, the program can’t see the difference without UB. In fact the compiler can also read from it, because it knows that it has in fact initialised that memory. And the compiler is not writing a C program and is thus not bound by the strictures of the C abstract machine anyway. | ||||||||||||||||||||||||||
| ▲ | foltik 10 hours ago | parent [-] | |||||||||||||||||||||||||
Yes yes, the spec says compilers are free to do whatever they want. That doesn’t mean they should. > The user didn’t initialize this integer. Let’s assume it’s always 4 since that helps us optimize this division over here into a shift… This is convenient for who exactly? Why not just treat it as a black box memory load and not do further “optimizations”? | ||||||||||||||||||||||||||
| ||||||||||||||||||||||||||