C++ to C conversion

T

tyapca7

hi all,
does anyone have an awk/sed/perl script to assist one with manual
rewriting from C++ to C?
(Class --> struct, method --> function, << >> to printf, etc...)
I have to rewrite a lot of legacy C++ code into a C-dialect of Plan 9
OS [sweetest Os around ;-) ]
http://plan9.bell-labs.com/plan9/

Thanks, regards,
++pac.
 
S

Stuart Redmann

hi all,
does anyone have an awk/sed/perl script to assist one with manual
rewriting from C++ to C?

I never thought anyone would want to do it this way (converting C to C++
is the usual case).
(Class --> struct, method --> function, << >> to printf, etc...)
I have to rewrite a lot of legacy C++ code into a C-dialect of Plan 9
OS [sweetest Os around ;-) ]
http://plan9.bell-labs.com/plan9/

If there is no C++ compiler around for Plan 9, I'll doubt very much that
this is a good OS.

Stuart
 
R

Rolf Magnus

hi all,
does anyone have an awk/sed/perl script to assist one with manual
rewriting from C++ to C?

How about using a C++ compiler that generates C code, like Comeau?
 
A

Adrian Hawryluk

hi all,
does anyone have an awk/sed/perl script to assist one with manual
rewriting from C++ to C?
(Class --> struct, method --> function, << >> to printf, etc...)
I have to rewrite a lot of legacy C++ code into a C-dialect of Plan 9
OS [sweetest Os around ;-) ]
http://plan9.bell-labs.com/plan9/

Why? Is the complexity of the C++ code too much for you and your team
to handle?

I've written some OO code in C before. It was a RT system, and I don't
think I need destructors on the auto 'object' variables (though there
/may/ have been some), since such code would have to be very carefully
constructed. C++ takes care of destruction of auto vars automatically,
making it somewhat easier in that regard.

A good chunk of the stuff I passed around were PODs[*], 98%-99% of them
constructed before runtime (static). Also, though I did careful cleanup
of all dynamically allocated 'objects', it wasn't all that critical
since once the system was running, nothing was deallocated. This is
because the operator would hit the off switch with no event propagated
to the computer. (Though if there was an event ever added, I
theoretically would have been able to recover all allocated memory and
done some additional cleanup on some resources.)

It was harder than C++ in some regards, easier in others. What was
harder was that I had to take in to account maintainability by others as
well, using plenty of wrapper functions, not requiring destructors being
called on stack allocated 'objects' (by making them PODs) and other
stuff. What was easier was that you knew _exactly_ what was going on.

Given everything that I just stated though, my question I put to you is
this: Do you *really* want to convert a C++ app that handled all the
destructors auto-magically, back to C? You might get more of a mess
than you started with when you start modifying the resulting code.

Just a thought.


Adrian

[*] Well everything in C is a POD, I actually mean that somewhat in the
spirit of C++. No destructor, (though I do allow for constructors
in a limited sense, where it doesn't allocate system resources),
etc...
--
_____________________________________________________________________
\/Adrian_Hawryluk BSc. - Specialties: UML, OOPD, Real-Time Systems\/
\ My newsgroup writings are licensed under a Creative Commons /
\ Attribution-Share Alike 3.0 License /
\_______[http://creativecommons.org/licenses/by-sa/3.0/]______/
\/_______[blog:_http://adrians-musings.blogspot.com/]______\/
 
D

Default User

Rolf said:
How about using a C++ compiler that generates C code, like Comeau?

That would be ok if you merely wanted to compile as C. If the goal is
to port C++ into maintainable C, then there's only one real tool for
that, a decent programmer familiar with both languages.




Brian
 
G

Greg Comeau

does anyone out there have an awk/sed/perl script to assist me with
manual rewriting from C++ to C?
(Class --> struct, method --> function, << >> to printf, etc...)

The problem with such a tool is that the gamut of the conversion
of C++ to C is not a 1-to-1 texttual mapping situation so it
wouldn't be done in awk/sed/perl. Therefore, ...
I have to rewrite a lot of legacy C++ code into a C-dialect of Plan 9
OS [sweetest Os around ;-) ]
http://plan9.bell-labs.com/plan9/

.... you would need a compiler. Comeau C++ does a C++ to C conversion
as an internal phase of translation. And would usually require no
manual rewriting. However, it would require a custom port.
Have a look at http://www.comeaucomputing.com and also email us.
 

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

No members online now.

Forum statistics

Threads
474,266
Messages
2,571,073
Members
48,772
Latest member
Backspace Studios

Latest Threads

Top