Chapter 17 Preprocessor Directives
Chapter 17 Preprocessor Directives
Fundamentals and
Programming in C
2nd Edition
Reema Thareja
1
© Oxford University Press 2016. All rights reserved.
CHAPTER 17
REPROCESSOR DIRECTIVE
Unconditional Conditional
define line undef include error pragma if else elif ifdef ifndef endif
• #define
• To define preprocessor macros we use #define. The #define statement is also known as macro definition
or simply a macro. There are two types of macros- object like macro and function like macro.
#undef
• As the name suggests, the #undef directive undefines or removes a macro name previously created with
#define. Undefining a macro means to cancel its definition. This is done by writing #undef followed by
the macro name that has to be undefined.
INSTRUCTION DESCRIPTION
COPYRIGHT To specify a copyright string
COPYRIGHT_DATE To specify a copyright date for the copyright string
HP_SHLIB_VERSION To create versions of a shared library routine
LOCALITY To name a code subspace
OPTIMIZE To turn the optimization feature on or off
OPT_LEVEL To set the level of optimization
VERSIONID To specify a version string
–The #endif directive ends the scope of the #if , #ifdef , #ifndef , #else , or #elif directives.
• The error messages include the argument string. The #error directive is usually used to detect
programmer inconsistencies and violation of constraints during preprocessing.
• When #error directive is encountered, the compilation process terminates and the message specified in
string is printed to stderr. For example,
• #ifndef SQUARE
• #error MACRO not defined.
• #endif
• #ifndef VERSION
#error Version number is not specified.
#endif