The C preprocessor is the first step of the code translation process. It performs some editing tasks before the compiler starts . With Standard C has come a number of useful and powerful techniques that make the preprocessor a genuinely useful tool to the C programmer. The preprocessor is a powerful but must be used carefully (pitfalls)

normally you don’t see the preprocessor output , you can see it by using the -E flag:

# gcc -E samp.c 1 # gcc -E samp.c

One duty of the preprocessor is to remove comments, and replace it with blank lines. If any header files are included, these will also appear in the preprocessor output. This can result in a lot of text. Some preprocessor identifiers: __LINE__ - Number of line being compiled __FILE__ - Name of file being compiled __DATE__ - Compilation date "mm dd yyyy" __TIME__ - Compilation time "hh:mm:ss" __func__ - Name of the current function 1 2 3 4 5 6 7 8 9 __LINE__ - Number of line being compiled __FILE__ - Name of file being compiled __DATE__ - Compilation date "mm dd yyyy" __TIME__ - Compilation time "hh:mm:ss" __func__ - Name of the current function For Example you can use it for debug: printf("Error in line %d in file %s

", __LINE__, __FILE__); 1 printf ( "Error in line %d in file %s

" , __LINE__ , __FILE__ ) ; Macros and pitfalls: If we define the following macro: #define MAX(a,b) (a>b)?a:b 1 #define MAX(a,b) (a>b)?a:b If we use it with simple parameters it will work fine but if we put some complexity it can cause some pitfalls for example: k = MAX(i++, j++); 1 k = MAX ( i ++ , j ++ ) ; Will expand to: k = ((i++) > (j++)) ? (i++) : (j++)); 1 k = ( ( i ++ ) > ( j ++ ) ) ? ( i ++ ) : ( j ++ ) ) ; The result is that one of the arguments will increment twice

Names conflicts

We can define a function with the same name as a predefined macro but we need to use parentheses :