Analyzing the discipline of preprocessor annotations in 30 million lines of C code

  • Authors:
  • Jörg Liebig;Christian Kästner;Sven Apel

  • Affiliations:
  • University of Passau, Passau, Germany;Philipps-University Marburg, Marburg, Germany;University of Passau, Passau, Germany

  • Venue:
  • Proceedings of the tenth international conference on Aspect-oriented software development
  • Year:
  • 2011

Quantified Score

Hi-index 0.00

Visualization

Abstract

The C preprocessor cpp is a widely used tool for implementing variable software. It enables programmers to express variable code (which may even crosscut the entire implementation) with conditional compilation. The C preprocessor relies on simple text processing and is independent of the host language (C, C++, Java, and so on). Language-independent text processing is powerful and expressive - programmers can make all kinds of annotations in the form of #ifdefs - but can render unpreprocessed code difficult to process automatically by tools, such as refactoring, concern management, and variability-aware type checking. We distinguish between disciplined annotations, which align with the underlying source-code structure, and undisciplined annotations, which do not align with the structure and hence complicate tool development. This distinction raises the question of how frequently programmers use undisciplined annotations and whether it is feasible to change them to disciplined annotations to simplify tool development and to enable programmers to use a wide variety of tools in the first place. By means of an analysis of 40 medium-sized to large-sized C programs, we show empirically that programmers use cpp mostly in a disciplined way: about 84% of all annotations respect the underlying source-code structure. Furthermore, we analyze the remaining undisciplined annotations, identify patterns, and discuss how to transform them into a disciplined form.