Usefulness of Const in C++ – Explained

c++constants

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?

Best Answer

The primary use of const isn't to generate better code, but to protect you from yourself, ensuring that you don't accidentally change something you didn't mean to.