Answer: Though, the preprocessor is the first to look at the source code file and performs several preprocessing operations before it’s compiled by the compiler. Nevertheless, compiler sets the source code file, say “hello.c”, through several phases of translation before jumps into preprocessing. Actually, it prepares the file for being preprocessed by preprocessor.
Firstly, it does mapping of characters in source code file to source character set. It takes care of multi-byte characters and trigraphs. Secondly, it locates character combinations of backslash ‘\’ followed by “newline character” and deletes them. For example, the two physical lines,
printf("hello \ world\n");
Newline character is one you get by pressing Enter key and not the character representation ‘\n’ or symbolic constant \n.
This preparation is a useful feature as preprocessor expressions are required to be one logical line. Although, each logical line can be one or more physical lines.
Next, compiler breaks the text into a sequence of tokens and sequences of white space and comments. A token is a group of words separated by white spaces. Then replaces each comment by single white space. For example,
int/* declaring an integer variable */value;
After this, prepocessor processes source code. Because it processes the source code before it is compiled hence it’s called preprocessor. It starts it’s work by deleting the comments, following the #directives including header files on your request, replacing the replacement text for macros and symbolic constants, telling the compiler which block of code to accept or ignore. Preprocessor doesn’t know C. It simply takes text of one type and converts it to some other type.
Sanfoundry Global Education & Learning Series – 1000 C Tutorials.