C2C++ convertor/tool

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 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.

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.

Now what to do with extern variables and function prototypes? Plus, isn’t C++
heavily strongly typed?

HELP!

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?

Probably, but what are you trying to accomplish with such a tool?

I know C is a subset of C++

C++ Is a superset of C… not the other way around.

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 wouldn’t think that it would help much to just “convert it”, as logical
grouping is something that is programmer/design driven rather than
something that can be automatically farmed.

Now what to do with extern variables and function prototypes? Plus,
isn’t C++ heavily strongly typed?

It’s much better at type checking, yes. You’d have to take those variables
and align them with their newfound classes. I don’t think there’s anything
that’ll do what you’re asking.

–>Neil-------------------------------------------------------------------------------
Neil Bradley "Your mistletoe is no match for my T.O.W. missile!"
Synthcom Systems, Inc. - Santabot - Futurama
ICQ #29402898

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++

Er… I don’t think this is technically advisable. It might not only be
difficult, but it may lead to a lot of bugs after converted.

Re-engineering is probably the way to go (rewriting the code). You look
at the code, understand it and dissect it and then rewrite it in C++…

But then again, you might want to consider long-term benefits of writing
a program which converts C code to C++ code. You might want to convert
other C programs to C++ in the future.

The choice is yours.

  • Akinwale Ariwodola

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 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.

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.

Now what to do with extern variables and function prototypes? Plus, isn’t C++
heavily strongly typed?

HELP!


SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl

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.

That’s a good idea. Basically the reason why I want it to be C++ is because of
the namespace. I want to nicely write extensions/modules without interrupting
the original source code, etc. hence OOP needed.

Just incase anyone else is interested in converting C to C++ I have found a
tool. Apparently it’s the only tool/script on the net.

http://www.scriptet.com/ctocpp.php

Happy trying and playing around with this thing. Now… lets see how long it
takes me to convert SDLdoom-1.10.tar.gz to C++ code…

Converting everything to C++ classes is still overkill. You can rename
your files to .cpp and just add namespace statements. Namespaces apply
equally well to functions as well as classes. The end result will be
much much cleaner.

Richard SchreyerOn May 4, 2004, at 8:59 AM, KevinGPO wrote:

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.

That’s a good idea. Basically the reason why I want it to be C++ is
because of
the namespace. I want to nicely write extensions/modules without
interrupting
the original source code, etc. hence OOP needed.

Just incase anyone else is interested in converting C to C++ I have
found a
tool. Apparently it’s the only tool/script on the net.

http://www.scriptet.com/ctocpp.php

Happy trying and playing around with this thing. Now… lets see how
long it
takes me to convert SDLdoom-1.10.tar.gz to C++ code…


SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl

Richard Schreyer <rws_list girr.org> writes:

Converting everything to C++ classes is still overkill. You can rename
your files to .cpp and just add namespace statements. Namespaces apply
equally well to functions as well as classes. The end result will be
much much cleaner.

Richard Schreyer

Yes that does sound easier and cleaner. I assume to use name spaces just write:

namespace space { } ?

I would have to go through all the files and strongly type cast - eliminating
those void* castings. Any easier way of doing that? like a script?

Converting everything to C++ classes is still overkill. You can rename
your files to .cpp and just add namespace statements. Namespaces apply
equally well to functions as well as classes. The end result will be
much much cleaner.

Richard Schreyer, sorry but I flicked through my ancient C++ book and could not
find anything about namespaces. It was however in my C# book. Was namespaces
something new added in in like C++99?

No, namespaces are part of the ANSI/ISO C++.

You book is probably too old and doesn’t cover the standard.
That is a normal situation with C++ books that got written while
the standardization process was evolving.

Just take a look at something that I wrote about it, a few years
ago.

http://www.progtools.org/compilers/tutorials/discovering_cxx/discovering_cxx.html#d36e87

Cheers,
Paulo Pinto

KevinGPO wrote:>>Converting everything to C++ classes is still overkill. You can rename

your files to .cpp and just add namespace statements. Namespaces apply
equally well to functions as well as classes. The end result will be
much much cleaner.

Richard Schreyer, sorry but I flicked through my ancient C++ book and could not
find anything about namespaces. It was however in my C# book. Was namespaces
something new added in in like C++99?


SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl

No, namespaces are part of the ANSI/ISO C++.

You book is probably too old and doesn’t cover the standard.
That is a normal situation with C++ books that got written while
the standardization process was evolving.

Just take a look at something that I wrote about it, a few years
ago.

Paulo Pinto, damn, you are right. And here’s me with my Learning C++ in 25days
book which was published in 1992. Damn, maybe I should get another up-to-date
book. Any recommendations?

I would just go for the Bjarne’s book:

*The C++ Programming Language

*just take the special edition because it has a few
more chapters,

Cheers,
Paulo

KevinGPO wrote:>>No, namespaces are part of the ANSI/ISO C++.

You book is probably too old and doesn’t cover the standard.
That is a normal situation with C++ books that got written while
the standardization process was evolving.

Just take a look at something that I wrote about it, a few years
ago.

Paulo Pinto, damn, you are right. And here’s me with my Learning C++ in 25days
book which was published in 1992. Damn, maybe I should get another up-to-date
book. Any recommendations?


SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl

This is off-topic. Please do not reply to the list.

Thanks,
-Sam Lantinga, Software Engineer, Blizzard Entertainment