[CSI] CS IA Question

Mikhail Nesterenko mikhail at cs.kent.edu
Mon Jan 22 22:36:02 EST 2018


> 
> I was reviewing the lecture notes earlier and was wondering about the
> effectiveness of literal constants in coding. Is there ever an instance
> where it would be advantageous to use a literal constant over a named
> constant?

The short answer is: "no". When creating the object code, a modern c++
compiler strips the name and replaces it with the value. So there is
no performance penalty for using a named constant rather than literal
constant. 

So, which constant to use is a matter of style. In most cases, named
constants are preferred.

Thanks,
--
Mikhail


More information about the cs13001 mailing list