title: Converting C source to C++
body: <p>How would you go about converting a reasonably large (>300K), fairly mature C codebase to C++?</p>
  
  <p>The kind of C I have in mind is split into files roughly corresponding to modules (i.e. less granular than a typical OO class-based decomposition), using internal linkage in lieu private functions and data, and external linkage for public functions and data. Global variables are used extensively for communication between the modules. There is a very extensive integration test suite available, but no unit (i.e. module) level tests.</p>
  
  <p>I have in mind a general strategy:</p>
  
  <ol>
  <li>Compile everything in C++'s C subset and get that working.</li>
  <li>Convert modules into huge classes, so that all the cross-references are scoped by a class name, but leaving all functions and data as static members, and get that working.</li>
  <li>Convert huge classes into instances with appropriate constructors and initialized cross-references; replace static member accesses with indirect accesses as appropriate; and get that working.</li>
  <li>Now, approach the project as an ill-factored OO application, and write unit tests where dependencies are tractable, and decompose into separate classes where they are not; the goal here would be to move from one working program to another at each transformation.</li>
  </ol>
  
  <p>Obviously, this would be quite a bit of work. Are there any case studies / war stories out there on this kind of translation? Alternative strategies? Other useful advice?</p>
  
  <p>Note 1: the program is a compiler, and probably millions of other programs rely on its behaviour not changing, so wholesale rewriting is pretty much not an option.</p>
  
  <p>Note 2: the source is nearly 20 years old, and has perhaps 30% code churn (lines modified + added / previous total lines) per year. It is heavily maintained and extended, in other words. Thus, one of the goals would be to increase mantainability.</p>
  
  <p>[For the sake of the question, assume that translation into <strong>C++</strong> is mandatory, and that leaving it in C is <strong>not</strong> an option. The point of adding this condition is to weed out the "leave it in C" answers.]</p>