CScout is a refactoring browser for C code that has been in the works for the past five years. When I set out to apply CScout on the Linux kernel source code, I discovered that it failed to correctly expand a couple of C macros, causing the analysis to fail. This prompted me to reimplement CScout's macro expansion using a precise functional specification, then optimize the code's severe degradation in time performance, and finally tidy up the optimized code mess. The work touched on many interesting subjects: correctness, performance, compiler optimizations, and readability. Although the domain I worked on is specialized, the lessons I learned have everyday applicability.
CScout (www.spinellis.gr/cscout) can process workspaces of multiple C projects, mapping the complexity introduced by the C preprocessor back into the original source code files. CScout takes advantage of modern hardware advances (fast processors and large memory capacities) to analyze C source code beyond the level of detail and accuracy provided by current compilers and linkers. For example, CScout lets you rename an arbitrary identifier in your code, and the change correctly propagates to exactly those source code elements (proper C code and macros) that form an equivalent correct code body. To satisfy this tall order, CScout incorporates in its code base a C preprocessor with parts of a compiler and a linker.