3 ms·
How can it both have no side effects and have undefined behaviour?
by asdfaoeu 2y ago
How can it both have no side effects and have undefined behaviour?
- masklinn 2y agoBy being declared as that? Division has no side effects, and division by 0 is UB. UBs only occur in invalid programs, so behaviour in case of UB is not relevant to a discussion of side effects or their lack thereof, in language terms these are not programs at all.
- asdfaoeu 2y agoIf print statement never completes then it is a well defined program. Because there will be no division by zero.
- sapiogram 2y agoBoth statements don't need to be true. The compiler just has to prove that at least one of the statements will always be true.
- asdfaoeu 2y agoTrue but it only has no side effects if it's well defined. The compiler can assume it's well defined but only if it's executed.