Type Here to Get Search Results !

The #ifndef Preprocessor Directive

The #ifndef Preprocessor Directive 

The syntax of the #ifndef directive is, as given below. 
#ifndef<identifier> 
statementl; 
statement2; 
#else 
statement3; 
statement4; 
}
 #endif 

The #ifndef, works exactly opposite to that of # ifdef. The #ifndef preprocessor, tests whether the identifier has defined substitute text or not. If the identifier is defined then #else block, is compiled and executed and the compiler ignores #if block. If the identifier is not defined, then #if block, is compiled and executed.

The #error Preprocessor Directive 
The # error, is used to display user defined message during compilation of the program. 
The syntax is, as given below. 
# if !defined (identifier) 
# error<ERROR MESSAGE> 
#endif 

Write a program to display user-defined error message using #error directive. 
# include <stdio.h> 
# include <conio.h> 
void main ()
#if !defined (A) 
# error MACRO A IS NOT DEFINED 
#else 
printf ("Macro found"); 
#endif 

Explanation: 
In the above program identifier 'A' is not defined. In the absence of the identifier, an error is generated and the # error directive displays the error message. The error message is user defined and displayed in the message box at the bottom of the editor.

Top Post Ad

Below Post Ad