Predefined Macros Program
#include<stdio.h>
#ifdef __STDC__
#define CONFORM “conforms”
#else
#define CONFORM “does not conform”
#endif
int main()
{
printf(“Line %d of file %s has been executed\n”,__LINE__,__FILE__); printf(“This file was compiled at %s on %s\n”,__TIME__,__DATE__); printf(“This program %s to ANSI standards\n”,CONFORM); }
Output:
Line 9 of file p1.c has been executed
This file was compiled at 13:36:39 on Mar 2 2021
This program conforms to ANSI standards
Other Directives
#error
This directive causes the preprocessor to generate an error message and causes compilation to fail.
Syntax:
#error error_string
Example:
#if SIZE %2==0
#error SIZE should not be an even number
#endif
If error occurred program compilation will not complete and therefore no executable program will be created.
Other Directives continued …
#pragma
This directive is used to specify options to the complier. These options are specific for the platform and the compiler. It tells compiler how it should process its inputs.
Following program will be supported by Turbo C but not run on GCC.
#include<stdio.h>
void func1();
void func2();
#pragma startup func1
#pragma exit func2
void func1()
{
printf(“\nInside func1()”);
}
void func2()
{
printf(“\nInside func2()”);
}
int main()
{
printf(“\nInside main()”);
return 0;
}
Output:
Inside func1()
Inside main()
Inside func2()
Comments
Post a Comment
Please give us feedback through comments