473,395 Members | 1,383 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

C++ to C conversion

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
5 1873
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
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Stub | last post by:
Docs says that "The compiler does not use an explicit constructor to implement an implied conversion of types. It's purpose is reserved explicitly for construction." I put up code of three cases...
7
by: Michael Lehn | last post by:
Hi, I have a question regarding the conversion of objects. When is the conversion done by the constructor and when by the operator. My feeling tells me that the constructor is preferred. But...
16
by: TTroy | last post by:
Hello, I'm relatively new to C and have gone through more than 4 books on it. None mentioned anything about integral promotion, arithmetic conversion, value preserving and unsigned preserving. ...
31
by: Bjørn Augestad | last post by:
Below is a program which converts a double to an integer in two different ways, giving me two different values for the int. The basic expression is 1.0 / (1.0 * 365.0) which should be 365, but one...
11
by: Steve Gough | last post by:
Could anyone please help me to understand what is happening here? The commented line produces an error, which is what I expected given that there is no conversion defined from type double to type...
2
by: Alex Sedow | last post by:
Why explicit conversion from SomeType* to IntPtr is not ambiguous (according to standart)? Example: // System.IntPtr class IntPtr { public static explicit System.IntPtr (int); public...
3
by: Steve Richter | last post by:
here is a warning I am getting in a C++ .NET compile: c:\SrNet\jury\JuryTest.cpp(55) : warning C4927: illegal conversion; more than one user-defined conversion has been implicitly applied while...
0
by: Lou Evart | last post by:
DOCUMENT CONVERSION SERVICES Softline International (SII) operates one of the industry's largest document and data conversion service bureaus. In the past year, SII converted over a million...
0
by: dataentryoffshore | last post by:
Get a Discount up to 60% on data entry, data capture, dataentry services, large volume data processing and data conversion services through offshore facilities in India. Offshore data entry also...
21
by: REH | last post by:
It it permissible to use the constructor style cast with primitives such as "unsigned long"? One of my compilers accepts this syntax, the other does not. The failing one chokes on the fact that the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.