KevinGPO wrote:
I want to write a program so that it opens a C project and links all the
dependencies, etc. views the project objectly. Then convert each C file to a
C++ class in one go, or one file to class at a time. Is this possible? Has this
idea already been done?
I have been writing a converter that scans gtk header files and extends
the structs to be proper c++ classes with all its methods. But that gtk
had been object oriented in the first place.
I know C is a subset of C++ and some of you might think - easy! just rename .c
file to .cpp. What am looking for is to encapsulate/wrapping a C file functions
into a C++ class. But obviously it’s not easy like that. We have to look at the
relationships between each C file in a massive C project/program.
That’s the real problem - in assigning functions to their classes. At best write
helper files that tell the relationship and make it a two phase process by
writing a number of detectors for the relationships, pump it up with manual
additions (e.g. operator overloading, default arguments), and have a converter
to spit out the c++.
I am wanting to convert the old classic SDLDoom-1.10 (which is purely 100% C)
into C++ (see source at www.doomworld.com sourceports download). We can take
each .c & .h couple and encapsulate/wrapup all the functions from the .c file
into the .h file in a class named after the file name.
I do not understand why you want to do that. Pushing away the c++ overhead
is always good for speed, and an engine should be speedy. Other that you told
above, C is not just a subset. It needs no constructor/destructor calls everywhere,
especially in building/dumping objects to be placed in call frames. What you might
want to have is c++ headers with methods being inline functions to directly link to
the fast C-based implementation based on the object referenes.
Now what to do with extern variables and function prototypes? Plus, isn’t C++
heavily strongly typed?
C99 is almost as strongtyped as C++. The only difference is that a C programmer
can assign anything from a void*
but C++ programmers can’.t (downcast needed).
You benefit from the object type hierarchy in c++ thereby avoiding explicit cast
operators and getting a bit of safety over non-matching types. - but such an OO
type relation has to exist in the first place in that API, you can’t just surgeon it.
HELP!
don’t shout - use your skills. Engineering is the art to create the things you
want from the things you can get.
cheers,
– guido http://google.de/search?q=guidod
GCS/E/S/P C++/++++$ ULHS L++w- N++@ s+:a d(±) r+@>+++ y++