364 Programming and Data Structures
Explanation In the above program #i f ndef checks for the identifier T. If it is defined the #else block
is executed. On execution of the block the output of the program is "Macro is defined". In case the
identifier is undefined the #else block is executed and output is " Macro is not defined."
11.8 THE * e r ro r DIRECTIVE
The # erro r is used to display user defined message during compilation of the program. The
syntax is as given below.
# i f 1d efin e d ( id e n t i f ie r )
# e r r o r <ERROR MESSAGE>
#e n d if
11.13 Write a program to display user-defined error message using #error directive.
# include <stdio.h>
# include <canio.h>
# define B 1
void m aln()
{
clrscr ();
#if!defitted(A)
terror M A C R O A IS N O T DE FIN ED ,
tielse
printf ("M a cro foun d .");
#endif
}
Explanation In the above program identifier ' B' is defined. In the absence of identifier an error is
generated and the # e r r o r directive displays the error message. The error message is user defined
and displayed in the message box at the bottom of the editor.
Tip The # d e f in ed directive will work exactly opposite to #! de f ined directive. The syntax is as
given below.
# i f defined (id e n t ifie r)
{
}
#else
# erro r <ERROR MESSAGE>
#endif
11.9 THE# lin e DIRECTIVE
The syntax of line directive is as follows.
#lin e <constant> [ < id en tifier> ]
Causes the compiler to imagine-the line number of the next source line as given by <constant>, and
< id e n t if ie r > gives the current input file. If c id e n t i f ie r > is absent, then the current file name
remains unchanged.
Example # lin e 15 pragma.c
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.145.35.194