3 ms·
> Const isn't really useful to the optimiser in any way, roughly all it does really is effect the overload resolution rules, and how the compiler maps staticall
by account42 5y ago
> Const isn't really useful to the optimiser in any way, roughly all it does really is effect the overload resolution rules, and how the compiler maps statically initialized data in to your final binary.
const on pointers and references is not useful at all, but const on variables is useful as it means the value is never allowed to change. For example:
const int x = 0;
do_something(&x);
return x; // Optimizer can assume that x == 0 here even if it knows nothing about do_something
See: https://godbolt.org/z/4T8M3eK1x https://godbolt.org/z/4T8M3eK1x