I would like to know what are advantages and disadvantages when using the optional const
qualifier when initializing non-ref/pointer variables with a copy of a value:
for example:
void f(const T v)
instead ofvoid f(T v) // v does not need to be changed
if (const int err = f()) {/*...*/}
instead ofif (int err = f()) {/*...*/}
- or even
void f() {const T* const v = p; /*...*/}
instead ofvoid f() {const T* v = p; /*...*/}
Is it just a matter of style? What does the C++11 standard use in its examples? Could not const
be an hint for the compiler to store the variables in some special read-only memory (in some implementations)?