I’m a const fiend, and I strive to make everything as const as possible.
I’ve tried looking at various dissassembly outputs from const and non const versions of functions, and I’ve yet to see a marked improvement however. I’m assuming compilers nowadays are able to do smart things with non const functions that could technically be const.
Are there still cases where const is useful at the machine level? Any examples?
As far as I know, the only effect of marking a function const is to allow the function to be called on a
constobject. There’s no optimization benefit.Herb Sutter has an article which discusses const and optimization in depth:
The one area that
constis useful at the machine level is when applied to data – const data might be able to be placed in non-writable memory.