Books/online resources on converting C to C++

  • Thread starter David Goldsmith
  • Start date
D

David Goldsmith

Any reference material recommendations discussing issues arising in
the reengineering of a legacy, structured-style C program to an OO C++
program?

DG
 
V

Victor Bazarov

David said:
Any reference material recommendations discussing issues arising in
the reengineering of a legacy, structured-style C program to an OO C++
program?

Three approaches I know of:

- Just do it(tm). Simply compile it with a C++ compiler and fix the
errors, if any. C++ is a multi-paradigm language, OO is but one of
them.

- Don't do it. Keep it C. If it worked until now, why change it?
IOW, don't fix what isn't broken.

- Total rewrite. You have to figure out the problem they solved and
re-solve it using a different model or a different implementation of
the same model.

Depending on many factors you use one or another approach, or a mix of
them.

I don't know any references (and why would there be, such problem does
not arise on a daily basis), but I am fairly sure that if you look in
the news archives (groups.google.com) you will find similar questions
asked and answered more than once.

Also, take a peek in comp.software-eng newsgroup, reengineering is more
of their domain than a language issue.

V
 
I

Ivan Vecerina

David Goldsmith said:
Any reference material recommendations discussing issues arising in
the reengineering of a legacy, structured-style C program to an OO C++
program?
The first step should be simple: just compile the code as C++, then
understand and fix any errors that will show up.

Beyond this, any change needs to be motivated by a specific goal.
If it works, don't touch it!

When changes are required, the right approach is project dependent.
Do you just need to introduce a base class interface so you can
add subclasses? Do you have to add an abstraction layer to port
the application to a new platform?
Language-independent references about code refactoring and (domain
specific) design patterns may provide some guidance.

Many C++ techniques can also help make the code more maintainable:
replace macros with inline functions and other constants; replace
function pointers with polymorphic interfaces; use constructors and
destructors instead of manual initialization/freeing; use RAII for
resource management; etc.

The main caveat when you have a mix of C++ and C style code is
error handling and memory management. As soon as a function
can generate (C++) exceptions, all calling code needs to be
exception-safe (e.g. use the RAII idiom).
This means that you need to carefully maintain interfaces
between C style and new C++ functions.


hth,
Ivan
 
I

Ivan Vecerina

Ivan Vecerina said:
....
Language-independent references about code refactoring and (domain
specific) design patterns may provide some guidance.
PS:
For technicalities and differences between C and C++, the following
links may be of interest:
http://www.research.att.com/~bs/papers.html (check the "C and C++...")
http://www.ece.utexas.edu/courses/fall_04/ee322c-15515/notes-from-c-to-c++.pdfBut the key is really to understand all the C++ idioms and techniquesyou can use, so you make the right choices when performing changes.
 
D

Don Kim

David Goldsmith said:
Any reference material recommendations discussing issues arising in
the reengineering of a legacy, structured-style C program to an OO C++
program?


I don't know of a particular reference, but the book "Thinking in C++"
Volume 1 is definetely a book for those comming to C++ from a C background.
You can download it for free too.

-Don Kim
 
D

David Goldsmith

Thanks!

As for the very good question (asked previously) "why do it at all?":
because I've been told to! Actually, what we want is to make the code
platform independent AND native using wxWidgets, and, due to extant
in-house expertise, it's to be done in C++; the extant C code has
actually been built using a C++ compiler, but it is devoid of OO
paradigmatic entities, e.g., classes. But, cognizant/empathetic of/to
the "If it ain't broke, don't fix it" viewpoint, I have already
queried my bosses regarding the importance of actually remaking the
whole thing (as opposed to any wxWidgets enhancements/re-do's) OO.

Thanks again!

DG
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top