Usefulness of const (C++)

前端 未结 6 1132
眼角桃花
眼角桃花 2021-01-18 23:43

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 fu

6条回答
  •  终归单人心
    2021-01-19 00:14

    I follow your strategy, and I see it's main usefulness as being to a human. I've adopted a very functional style in a lot of my programming, and const helps enforce that and illustrate that to other programmers who might be reading my code.

    In truth, I see some of the new function attributes that C++0x is going to support as being a little more useful for compilers. Knowing that the result of a function depends solely on its arguments, and does not follow any pointers passed to it means that calls to the function can be subjected to CSE.

提交回复
热议问题