C ++ Directive on Macro Definitions and Conditional, Additional Directives
C ++ Directive on Macro Definitions – A macro is a piece of code that has been given a name. Macros are pieces of code in a program that have been given names. As the compiler encounters the name, it replaces the name with the real item of code.
#define
This command is used to define symbolic constants. Create a macro name code.
#undef
The #undef directive may be used to close macros defined with the #define statement when the program is no longer defined. When a program is no longer defined, using a macro (defined by #undef) will result in compilation errors.
Conditional Directives Compilation in C ++
#elif
#ifdef
#if
#endif
#ifndif
#ifndef
#else
The # and double # operators are used to turn a text token into a string.
Additional directories in C ++
- #error: When the compiler finds a problem in the source code, it generates an error message in the error directory.
- #line: This directive informs the compiler to change the compiled filename and line number with the supplied ones.
- #pragma: It provides instructions for putting it into action.
The C++ programming language provides a number of directives, also known as preprocessor commands, which can be used to control the compilation process. One of the most important of these is the #define directive, which can be used to create macro definitions. A macro definition is simply a replacement for a certain sequence of characters. For example, the following macro definition would cause the text “Hello, world!” To be replaced by “Hello, world!” Every time it appears in the program:
#define hello "Hello, world!"
The #define directive can also be used to create conditional compilation directives. These directives allow the programmer to specify that certain lines of code should only be compiled if a certain condition is met. For example, the following directive would cause the text “This line will be compiled.” To be compiled only if the symbol DEBUG is defined:
#ifdef DEBUG std::cout << "This line will be compiled." << std::endl; #endif
There are a number of other directives available in C++, including the #error and #warning directives, which can be used to generate error and warning messages during compilation, and the #pragma directive, which can be used.