Wireshark-dev: Re: [Wireshark-dev] Idle Thought - Compiling with C++
From: Ed Beroset <beroset@xxxxxxxxxxxxxx>
Date: Sun, 10 Feb 2013 09:06:58 -0500
Donald White wrote:
That said, I have some experience with C to C++ transitions.  Twice in
my career, the team I was with was given the job of maintaining legacy
products written in C (several 100K lines of code) to maintain and
enhance.  In both cases, our first step was to recompile with a C++
compiler.  This was done as a quick and intense effort without
introducing any C++ language features.  We would just get the code to
compile, link and pass its regression tests.  Only later did we replace
#defines with consts, macros with inline functions and such.  I judged
these efforts as being very beneficial in improving code quality.

This is a reasonable approach for improving code quality. In an open source project like Wireshark, I think the challenge would be in specifying which C++ features/constructs would NOT be used. Having extensive experience with both C++ and C, I'd say that some of the most useful features in C++ didn't even exist in 1991 when that "Old dogs, new tricks" article was written. Specifically, I mean templates and the Standard Template Library (STL). That said, however and at the risk of stating the obvious, code written in C++ looks a lot different than C written in C++.

For example, to me, the tvbuff.c and value_string.c files cry out for reimplementation as C++ classes, but to actually do such a reimplementation would very literally be a change to the core of Wireshark. If we were to use a C++ compiler as simply an enhanced C compiler, we'd have to figure out how to prevent submissions from including C++ constructs no "approved" by Wireshark coding guidelines.

Ed