ANSI committee has added some more preprocessor directives to the existing directives discussed so far. They are:
For example, let us consider a macro is named as NAME.
#elif provides alternative test facilities
#pragma Specifies certain instruction
#error Stops compilation when an error occurs
The ANSI standard also includes new preprocessor operations
# stringizing operator
## Tokenpasting operator
The #elif directive means else if and establishes an if-else-if chain for multiple compilation options. #elif is followed by a constant expression. If the expression is true, that block of code is compiled and no other #elif expression is tested. Otherwise the next block in the series is checked.
The #pragma directive is an implementation-defined directive that allows various instructions to be given to the compiler. If the implementation was not expecting what is written, it is ignored.
This directive is followed by one or more tokens at the end of the line. A diagnostic message is produced by the compiler, which includes those tokens, but no further detail is given in the standard .it might be used like this to abort a compilation on unsuitable hardware:
#include <limits.h>
#if CHAR_MIN > -128
#error character range smaller than required
#endif
Which would be expected to produce some sort of meaningful compilation error and message.
There is special treatment for places in the macro replacement string where one of the macro formal parameters is found preceded by #. The token list for the actual argument has any leading or trailing white space discarded, then the # and the token list are turned in to a single string literal. Spaces between the tokens are treated as space characters in the string. To prevent ‘unexpected ‘ results, any” or / characters with the new string literal are preceded by /.
A ## operator may occur anywhere in the replacement text for a macro except at the beginning or end. If a parameter name of a function macro occurs in the replacement text preceded or followed by one of these operators, the actual token sequence for the corresponding macro argument is used to replace it. Then for both function and non-function macros, the token surrounding the ## operator are joined together. If they don’t form a valid token,the behaviour is undefined. Then rescanning occurs.
Silan Software is one of the India's leading provider of offline & online training for Java, Python, AI (Machine Learning, Deep Learning), Data Science, Software Development & many more emerging Technologies.
We provide Academic Training || Industrial Training || Corporate Training || Internship || Java || Python || AI using Python || Data Science etc