Teachers Paradise School Supplies Teacher Resources Free Encyclopedia
Teachers Paradise FREE Teaching Resources
Home Arts Crafts Audio Visual Equipment Office Supplies Teacher Resources
Main Page | Edit this page

Preprocessor

A preprocessor is a program that takes text and performs lexical conversions on it. The conversions may include macro substitution, conditional inclusion, and inclusion of other files.

The C programming language has a preprocessor that performs the following transformations:

  1. Replaces trigraphs with equivalents.
  2. Concatenates source lines.
  3. Replaces comments with whitespace.
  4. Reacts to lines starting with an octothorp (#), performing macro substitution, file inclusion, conditional inclusion, and other transformations.

Overuse of the C preprocessor is considered bad style, especially in C++. Stroustrup introduced features such as templates into C++ in an attempt to make the C preprocessor irrelevant. However, his file inclusion alternative was never seriously considered as it was a poor imitation of the C preprocessor's file inclusion mechanism.

Other preprocessors include m4 and Oracle Pro*C. The m4 preprocessor is general-purpose; Oracle Pro*C converts embedded PL/SQL into C.

Preprocessing can be quite cumbersome in incremental parsing or incremental lexical analysis because changes to preprocessing rules can affect the entire text to be preprocessed.

C Example

A typical example in C is:

\r\n#include \r\n\r\nint main (void)\r\n{\r\n    printf("Hello, world!\\n");\r\n    return 0;\r\n}\r\n
The preprocessor replaces the line #include <stdio.h> with the system header file of that name, which facilitates use of the printf() function.



Pay for Educational Supplies & Teaching Supplies with Visa, Master Card, American Express, Discover or Paypal.
TeachersParadise.com HOME | Safe Shopping Guarantee | Help Desk
All trademarks & brands are the property of their respective owners.
Legal Notice 2000-2008 TeachersParadise.com, Inc. All Rights Reserved