[comp.lang.c++] const Performance benefits {Was: const is not object-oriented}

rpk@rice-chex.ai.mit.edu (Robert Krajewski) (11/17/90)

I'm no language innocent, but I'm not familiar with the performance
benefits of using const.  (I'm certainly aware of the safety
benefits.)

The only one I could think of is that the compiler could re-order
function calls in expressions.

----
Robert P. Krajewski
Internet: rpk@ai.mit.edu ; Lotus: robert_krajewski.lotus@crd.dnet.lotus.com

steve@taumet.com (Stephen Clamage) (11/18/90)

rpk@rice-chex.ai.mit.edu (Robert Krajewski) writes:

!I'm no language innocent, but I'm not familiar with the performance
!benefits of using const.  (I'm certainly aware of the safety
!benefits.)
!The only one I could think of is that the compiler could re-order
!function calls in expressions.

It allows a number of optimization opportunities.

The major one is that unless declared extern, a const scalar type need
not be assigned to memory, and if the definition is visible the literal
value may be used instead of reading it from storage.
-- 

Steve Clamage, TauMetric Corp, steve@taumet.com