2006-03-14

Constant for large values of X

No doubt you have started out creating constant values using the statement '#define VALUE=5'. The problem with this is that most debuggers will not be able to report this constant value. The fact that the preprocessor has processed this statement before the debug symbols are gathered is one reason for this.

A better way to represent constant values is to use the const keyword. (Final in Java.) One advantage is that any type of variable can be called constant, and this includes user defined structures.

If you would rather have the constant value have class scope, using the enum keyword is the way to go. You cannot use a variable type other than integer, but you can reference the value through the containing class, e.g. myClass::constVal.

No comments: