tool(s) or white paper to convert "c++" code to "c" 
Author Message
 tool(s) or white paper to convert "c++" code to "c"


Quote:

> I was told that there is a white paper or howto that helps in converting "c++"
> code to "c". I  need to convert  a failry complicated and big  "c++" application to
> "c" under tight deadlines. Any help or pointers will be highly appreciated.
> Thanks in advance-

> Sanjay Sharma


Sanjay,
   If the original programs (C++) use virtual functions, a conversion to
 c will be very complex. C does not allow for polymorphysm like c++. I
don't know of a c compiler that does run time binding and automatic
up/downcasting. Even if there is no polymorphic traits inherent in the
original program, the conversion will be tough.(to say the least)
                        Good Luck
                        Bill


Sun, 14 Feb 1999 03:00:00 GMT  
 tool(s) or white paper to convert "c++" code to "c"

I was told that there is a white paper or howto that helps in converting "c++"
code to "c". I  need to convert  a failry complicated and big  "c++" application to
"c" under tight deadlines. Any help or pointers will be highly appreciated.
Thanks in advance-

Sanjay Sharma



Mon, 15 Feb 1999 03:00:00 GMT  
 tool(s) or white paper to convert "c++" code to "c"

Quote:


>> I was told that there is a white paper or howto that helps in converting "c++"
>> code to "c". I  need to convert  a failry complicated and big  "c++" application to
>> "c" under tight deadlines. Any help or pointers will be highly appreciated.
>> Thanks in advance-

>> Sanjay Sharma

>Sanjay,
>   If the original programs (C++) use virtual functions, a conversion to
> c will be very complex. C does not allow for polymorphysm like c++. I

Not really; that can be done readily with function pointers, which is what
virtual functions really are (or at least, that is how they are implemented).
This if I have a class Foo, and a derived class Bar which overrides a virtual
function in Foo with its own, all that happens is that a function pointer
in some sort of table is modified. A Bar object can be passed to modules which
were designed to work on Foo, and these modules can call the new function
because they dereference a function pointer.

Quote:
>don't know of a c compiler that does run time binding and automatic
>up/downcasting. Even if there is no polymorphic traits inherent in the
>original program, the conversion will be tough.(to say the least)

The Cfront program is a C++ to C translator. The HP-UX 'CC' compiler uses
Cfront. If I had this handy, I'd show you what a translation looks like.

C++ is just smoke and mirrors.



Mon, 15 Feb 1999 03:00:00 GMT  
 tool(s) or white paper to convert "c++" code to "c"



Quote:

>I have to wonder WHY anyone would write something in C++ and want
>to turn it into C in the first place, though.

So that you can run C++ code on your DSP chip, which only has a C compiler.
In fact, the earliest C++ compilers (for any computer) compiled _only_ to C.
It was a "breakthrough" in technology to compile _directly_ to machine code.

If I have my facts straight, the first commercial C++ compiler for the PC,
Zortech (1988), did in fact compile to machine code, but then PC != world.

--




Mon, 15 Feb 1999 03:00:00 GMT  
 tool(s) or white paper to convert "c++" code to "c"

:    If the original programs (C++) use virtual functions, a conversion to
:  c will be very complex. C does not allow for polymorphysm like c++. I
: don't know of a c compiler that does run time binding and automatic
: up/downcasting. Even if there is no polymorphic traits inherent in the
: original program, the conversion will be tough.(to say the least)

Yes, it would be bad, because you'd have to essentially create the
virtual function table setup yourself. The compiler does it behind
your back. It would not be simple, and wouldn't be as bug free as
a compiler's that had been around a few years.

The book Object Oriented Programming in C++, an orange book from Sams
(which I don't think is in print any more, which is bad because it's a
GREAT book, one of the lesser known but great C++ books), discusses a C
implementation of C++ (for the purposes of the text to teach how C++
works to C programmers in terms they know already, but it's useful for
other reasons).

If you get into templates, namespaces, exception handling, etc
you might as well forget it.

I have to wonder WHY anyone would write something in C++ and want
to turn it into C in the first place, though.

Scott



Mon, 15 Feb 1999 03:00:00 GMT  
 tool(s) or white paper to convert "c++" code to "c"


: I  need to convert  a failry complicated and big  "c++" application to
: "c" under tight deadlines.

It took a while for this question to sink in -- *WHY* would anyone
want to do this?! You don't write a fairly compilcated program and
then try to instantly turn it into another language.

Scott



Mon, 15 Feb 1999 03:00:00 GMT  
 tool(s) or white paper to convert "c++" code to "c"

Hi,

: I was told that there is a white paper or howto that helps in converting "c++"
: code to "c". I  need to convert  a failry complicated and big  "c++" application to
: "c" under tight deadlines. Any help or pointers will be highly appreciated.
: Thanks in advance-

If you just need the C code, you might get away with a C++ compiler
which produces C as intermediate code during compilation. Apparently,
Photon C++ does this. However, I don't have any ideas on whether the
intermediate code might be used for something (i.e. whether it is legal
to use it for whatever...).

If you need to convert the C++ code to maintainable C code, I suggest
that you have a look at the style how Xt (the X11 Toolkit) is
implemented: There, object oriented concepts including a mechanism
similar virtual functions is used. This might help in the
conversion...
--

<http://www.informatik.uni-konstanz.de/~kuehl/>
I am a realistic optimist - that's why I appear to be slightly pessimistic



Tue, 16 Feb 1999 03:00:00 GMT  
 tool(s) or white paper to convert "c++" code to "c"



Quote:

>: I  need to convert  a failry complicated and big  "c++" application to
>: "c" under tight deadlines.

>It took a while for this question to sink in -- *WHY* would anyone
>want to do this?! You don't write a fairly compilcated program and
>then try to instantly turn it into another language.

Really? I guess I better stop compiling my programs and just give people
hard copies of the source code... :)


Tue, 16 Feb 1999 03:00:00 GMT  
 tool(s) or white paper to convert "c++" code to "c"

Hi,
: So that you can run C++ code on your DSP chip, which only has a C compiler.

But then there is g++: If you need a C++ compiler (or even C compiler)
where there is no C++ compiler yet (well, actually it doesn't matter
whether there is a compiler at all as you can setup g++ to do
cross-compiling), you can get gcc, write the necessary description
files, et voila. I would not pretend that it is easy to write the
description files for g++ (I have never done it myself) but I would
expect that you might be better off with this approach... Writing
virtual functions and inheritance in C is not easy either and it is
very error prone: I have done this by writing Widgets for Xt (X
Toolkit) which basically implements some OO concepts in C.

If you think you won't get gcc to work on the platform you want C++ to
be available on, you can contact Cygnus Support for help on this
matter: This is basically what they are offering. You can get [paid, of
course] support to do with GNU tools what you need.

: In fact, the earliest C++ compilers (for any computer) compiled _only_ to C.
: It was a "breakthrough" in technology to compile _directly_ to machine code.

There are still compilers which at least can produce C as intermediate
code. I was recently quite surprised that Photon C++ (see
<http://www.kai.com> for more information) apparently produces
intermediate C code (although it is basically unreadable). At least,
this could solve the problem if it is legal to take the intermediate
code and compile it on a different machine (I don't know; you should
ask KAI's very good service...).

: If I have my facts straight, the first commercial C++ compiler for the PC,
: Zortech (1988), did in fact compile to machine code, but then PC != world.

GNU's g++ was the first C++ compiler producing machine language instead
of intermediate code: It was first released in December 1987. Zortec
shipped their compiler first in June 1988. Although GNU produces a free
compiler, they were the first (amazing isn't it?)! See the D&E for more
information.
--

<http://www.informatik.uni-konstanz.de/~kuehl/>
I am a realistic optimist - that's why I appear to be slightly pessimistic



Tue, 16 Feb 1999 03:00:00 GMT  
 tool(s) or white paper to convert "c++" code to "c"



Quote:
> I was told that there is a white paper or howto that helps in converting "c++"
> code to "c". I  need to convert  a failry complicated and big  "c++"
application to
> "c" under tight deadlines. Any help or pointers will be highly appreciated.
> Thanks in advance-

The program "cfront" comes to mind, but that probably isn't what you had
in mind.  The biggest problem is that "cfront" is a software product and
costs $$$ from whoever sells it now.  I don't think there is a free/low
cost option.

Manual translation comes to mind, but that looks contra-indicated given
"tight deadlines".

Good luck.

--
Tom Watson



Tue, 16 Feb 1999 03:00:00 GMT  
 
 [ 10 post ] 

 Relevant Pages 

1. remove() vrs fopen("""w")

2. Displaying binary data as ascii "1"'s and "0"'s

3. Looking for "Shroud"/"Obfus"

4. ""help with TSR""

5. Parse trees and "("")"

6. Error "free"-ing "malloc"-ed memory

7. Displaying binary data as ascii "1"'s and "0"'s

8. Tools for determining "code coverage"?

9. Help!!About the "White Space"

10. Attention "C"/"C++" gurus and "C" newbees

11. merits of "#define", "const", and "enum" ???

12. why not "cout", "<<" , and "endl"??

 

 
Powered by phpBB® Forum Software