c preprocessor (Part 2)
3.# undef
suppose you have something like this..
although the output is 5 you can’t trust these type of declarations.If you want to redefine the same macro then first undefine it using
#undefcorrect way of doing
03 | # undef x // x is now unknown to compiler |
05 | # define x 9 // x is 9 now |
so if you have your own macros and you are in doubt that their names can conflict with the macros defined in header files then first use # undef to undefine these macros.
1 | # undef conflictingname // undefining macro conflictingname in a headerfile. |
3 | # define conflictingname |
1 | # undef anyname // not an error |
4.# pragmaThe directive is a compiler specific directive which compiler vendors may provide .
1 | # pragma GCC poison x //variable cannot be used |
here
GCC poison is called pragmas.Remember these are compiler dependent.
So GCC poison will not work on microsoft compilers (will not give an error).You have to read manual of the compiler.
Predefined macro
working example
01 | # define _LINE_ 98 // error predefined cannot be redefined |
05 | printf ( "%d\n" ,__LINE__); |
06 | printf ( "%s\n" ,__FILE__); |
07 | printf ( "%s\n" ,__DATE__); |
08 | printf ( "%s\n" ,__TIME__); |
09 | printf ( "%d\n" ,__STDC__); |
0 comments:
Post a Comment