3 ms·
Seems like a reasonable compiler would inline the most likely implementation as 1. So, while technically undefined, it's safe to assume that it will 'return' 1
by jcwayne 5y ago
Seems like a reasonable compiler would inline the most likely implementation as 1. So, while technically undefined, it's safe to assume that it will 'return' 1 regardless of the actual on/off state of the computer.
- jeremyjh 5y agoI agree on the implementation, but I'm pretty sure if the computer is off you aren't getting a 1.
- yholio 5y ago{return 1;} is clearly a faulty implementation, it's entirely possible that the computer is already turned off by the time the function is executed using power stored in the decoupling capacitors of the CPU.
- azundo 5y agoSince the behavior is undefined when the computer is off this implementation seems correct in your hypothetical as well.
- josefx 5y agoI would be unreasonable. The power state appears to me as highly asynchronous to program execution. I see no explicit guarantees on how the state is retrieved or synchronized, without synchronization the state wont be properly updated. We know that the computer was of at some point, so it starts of as undefined. Given undefined as starting state and the lack of update guarantee we can assume that it will always return an undefined value. This opens up a lot more optimization possibilities than assuming a 1.