Synopsis: | Do not define macros instead of constants, enums, or type definitions |
Language: | C++ |
Severity Level: | 7 |
Category: | Preprocessor |
Description: |
A disadvantage of macros is that they can have side-effects and that they are not type-safe. In C++ alternatives exists that do not have these drawbacks. An alternative for a macro constant is the use of a const or enum, as in: #define MAX_BUFFER_LENGTH 1000 // Not ok. const ULONG ulMaxBufferLength = 1000; // Ok. enum {MAX_BUFFER_LENGTH = 1000}; // Ok. |