Understanding preprocessors
A preprocessor applies a transformation to source code. Some preprocessors are stand-alone tools, usable by and independent of any programming language tool. The most famous of these is probably the Unix m4 preprocessor. However, most preprocessors are tied to, associated directly with, and often integrated into a particular programming language and apply the transformation before the language compiler reads it in for lexical analysis. The output code from a preprocessor usually resembles its input with only a few changes, so you might wonder: why bother? Usually, the reason is that the judicious use of a preprocessor can make the code shorter and more readable.
A typical preprocessor transformation might be to replace all occurrences of some symbolic abbreviation such as PI
with 3.1415
. Another typical preprocessing example would be to expand some function-like syntax with parameters at compile-time, such as replacing occurrences of CUBED(X)
with ...