4 ms·
const helps optimization in exactly one case: global data. Adding const there requires the value to be a compile-time constant, and guarantees the optimizer ca
by brigade 15y ago
const helps optimization in exactly one case: global data.
Adding const there requires the value to be a compile-time constant, and guarantees the optimizer can inline the value rather than reading from memory. Though it still can inline the value in many cases if it can prove the variable isn't modified.
Of course, this precludes conditional constructs such as the one proposed by excuse-me; that only works as a local var and the const is again irrelevant to the optimizer.