2 ms·
> Since the width of the operands are known ahead of time, a wider integer can be unconditionally reserved on the stack for the result of the operation. What i
by munificent 4y ago
> Since the width of the operands are known ahead of time, a wider integer can be unconditionally reserved on the stack for the result of the operation.
What is the width of `i` in:
foo(int count) {
int i = 0;
for (int j = 0; j < count; j++) {
i = i + i;
}
}
- zmgsabst 4y agoYou probably want i=1 since i=0 is an answer you can predict: i = 0 implies that i = 0 + 0 = 0; so the loop doesn’t evolve, and the whole thing can be optimized to just i = 0. For i=1, the loop simplifies to 2^count and a count-length type, which is the point I think you wanted.
- munificent 4y agoHeh, oops, yes. :)