Utility const (C ++)

I am a competitive devil, and I try to do everything as const as possible.

I tried looking at the various disassembly outputs from the const and non const versions of functions, and I still see a noticeable improvement. I assume that compilers these days are capable of doing smart things with non-const functions, which can be technically const.

Are there any other cases where const is useful at the machine level? Any examples?

+5
source share
6 answers

As far as I know, the only effect of marking a const function is the ability to call a function on an object const. There are no optimization benefits.

Herb Sutter has an article discussing const and depth optimization:

, const , - const .

+9

const - , , , , .

+18

const, . , const_cast , ( , , , , const , )

, mutable . const , , mutable?

, , , - , , const , , , .

, , const , , , const , . , , .

+12

const - . - const, , : -, .

+2

, .

const , , , , , .

  • const const.
  • const , .
  • const , -, , .
+2

, . , const , .

, , ++ 0x . , , , , CSE.

+1

All Articles