At first I feel that I have to defend myself. I know that I probably should not worry about this, premature optimization, and what not. I know. I ask about this solely because I am curious and cannot (or do not know how) find a solution on my own.
Is it common practice for compilers to optimize constant integer division? Something like that:
const int FOUR = 4; const int TWO = 2; int result = FOUR / TWO;
Optimized:
const int FOUR = 4; const int TWO = 2; int result = 2;
Edit: I understand very well that the answer varies from compiler to compiler, I'm mostly wondering if its normal practice.
source share