|
Macros are ubiquitous in C, but used much less often in C++ programs. Macros are created by the preprocessor directive #define. Here is an example from C:
#define ARRAY_SIZE 1000
This definition would cause the C pre-processor to replace every occurrence of the name ARRAY_SIZE to be replaced by the number 1000. And if someday there was a need to change ARRAY_SIZE, one would need to edit only one line in the program, the line where the macro ARRAY_SIZE is defined.
Notwithstanding the obvious usefulness of macros for creating program constants, they tend to reduce the performance of C++ software tools such as debuggers, profilers, cross-reference tools, and so on, and their use is discouraged by Stroustrup [54]. In C++, a constant such as ARRAY_SIZE would be created by using the const modifier in a declaration, as in
const int ARRAY_SIZE = 1000;
|