By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,750 Members | 1,214 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,750 IT Pros & Developers. It's quick & easy.

C++ to C conversion

P: n/a
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.

Mar 22 '07 #1
Share this Question
Share on Google+
5 Replies


P: n/a
ty*****@gmail.com wrote:
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
Mar 22 '07 #2

P: n/a
ty*****@gmail.com wrote:
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?

Mar 22 '07 #3

P: n/a
ty*****@gmail.com wrote:
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/]______\/
Mar 22 '07 #4

P: n/a
Rolf Magnus wrote:
ty*****@gmail.com wrote:
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?
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
Mar 22 '07 #5

P: n/a
In article <11*********************@n76g2000hsh.googlegroups. com>,
<ty*****@gmail.comwrote:
>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.
--
Greg Comeau / 20 years of Comeauity! Intel Mac Port now in beta!
Comeau C/C++ ONLINE == http://www.comeaucomputing.com/tryitout
World Class Compilers: Breathtaking C++, Amazing C99, Fabulous C90.
Comeau C/C++ with Dinkumware's Libraries... Have you tried it?
Mar 22 '07 #6

This discussion thread is closed

Replies have been disabled for this discussion.