The #define directive
A preprocessor define directive directs the preprocessor to replace all subsequent occurrences of a macro with specified replacement tokens.
The
#define directive can contain:
The following are some differences between
#define and
the const type qualifier: - The
#definedirective can be used to create a name for a numerical, character, or string constant, whereas aconstobject of any type can be declared. - A
constobject is subject to the scoping rules for variables, whereas a constant created using#defineis not. - Unlike a
constobject, the value of a macro does not appear in the intermediate source code used by the compiler because they are expanded inline. The inline expansion makes the macro value unavailable to the debugger. - A macro can be used in a constant expression, such as an array
bound, whereas a
constobject cannot.
The
compiler does not type-check a macro, including macro arguments.
Related information
