11 ms·
That isn't what is meant by "side effect" here. A function with no side effects only modifies its local variables and returns a result. So, if we have int foo(
by not2b 3y ago
That isn't what is meant by "side effect" here. A function with no side effects only modifies its local variables and returns a result. So, if we have
int foo(int a, int b) {
int c = bar(a);
return b;
}
and we can see bar's body, and therefore we can determine that it has no side effects, we can optimize the call to bar away, because we can assume that it terminates and it doesn't affect the result.
But if bar writes to global variables, that's a side effect. If we can't see the body of bar we have to assume that it might.
- tester756 3y agoI'm aware, but I don't agree that we should ignore "physical world" implications We got hurt by that in side-channel attacks.
- aidenn0 3y agoGoing by that rule, optimizing compilers just shouldn't exist. Optimizations will (or at least are supposed to) decrease computation, which will affect CPU temperatures.