An empirical analysis of C preprocessor use

Download: PDF, implementation.

“An empirical analysis of C preprocessor use” by Michael D. Ernst, Greg J. Badros, and David Notkin. IEEE Transactions on Software Engineering, vol. 28, no. 12, Dec. 2002, pp. 1146-1170.
A previous version appeared as University of Washington Department of Computer Science and Engineering technical report UW-CSE-97-04-06, (Seattle, WA), April 22, 1997. Revised March 31, 1999.


This is the first empirical study of the use of the C macro preprocessor, Cpp. To determine how the preprocessor is used in practice, this paper analyzes 26 packages comprising 1.4 million lines of publicly available C code. We determine the incidence of C preprocessor usage — whether in macro definitions, macro uses, or dependences upon macros — that is complex, potentially problematic, or inexpressible in terms of other C or C++ language features. We taxonomize these various aspects of preprocessor use and particularly note data that are material to the development of tools for C or C++, including translating from C to C++ to reduce preprocessor usage. Our results show that while most Cpp usage follows fairly simple patterns, an effective program analysis tool must address the preprocessor.

The intimate connection between the C programming language and Cpp, and Cpp's unstructured transformations of token streams, often hinder programmer understanding of C programs and tools built to engineer C programs, such as compilers, debuggers, call graph extractors, and translators. Most tools make no attempt to analyze macro usage, but simply preprocess their input, which results in a number of negative consequences; an analysis that takes Cpp into account is preferable, but building such tools requires an understanding of actual usage. Differences between the semantics of Cpp and those of C can lead to subtle bugs stemming from the use of the preprocessor, but there are no previous reports of the prevalence of such errors. Use of C++ can reduce some preprocessor usage, but such usage has not been previously measured. Our data and analyses shed light on these issues and others related to practical understanding or manipulation of real C programs. The results are of interest to language designers, tool writers, programmers, and software engineers.

Download: PDF, implementation.

BibTeX entry:

   author = {Michael D. Ernst and Greg J. Badros and David Notkin},
   title = {An empirical analysis of {C} preprocessor use},
   journal = {IEEE Transactions on Software Engineering},
   volume = {28},
   number = {12},
   pages = {1146--1170},
   month = dec,
   year = {2002}

(This webpage was created with bibtex2web.)

Back to Michael Ernst's publications.