Skip to main content
Participant
July 31, 2014
Question

What is the efficiency of const

  • July 31, 2014
  • 1 reply
  • 237 views

Is any optimization done with operations involving constants, particularly converting operations with const to literal values.

I know the C++ compiler will effectively (not literally) convert this code:

const int VALUE_1 = 5;

const int VALUE_2 = 2;

int value3 = VALUE_1 + VALUE_2;

into something like this:

int value3 = 7;

This saves the program from adding 5 and 2 together while the program is running. I know that AS3 with flash is an interpreted language, so I'm not sure if the same can be done with it.

Does any optimization take place with const when declared on the method or class levels?

This topic has been closed for replies.