[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 342
  • Last Modified:

porting C++ to C in VC6

I have written a C++ app with VC6, and I want to convert all my C++ files to C.  I am trying to generate a console application on an AIX UNIX machine, and I only have a C compiler to work with.  I seem to remember hearing that VC6 had a utility or setting to do the conversion.  Any ideas?
0
danbind
Asked:
danbind
  • 5
  • 5
  • 2
  • +2
1 Solution
 
danbindAuthor Commented:
Edited text of question.
0
 
jhanceCommented:
You realize, of course, that gpp (the GNU C++ compiler and companion to gcc) is available for AIX.
0
 
nietodCommented:
VC does not have a C++ to C source code conversion utility.

However in addition t be a C++ com[piler, VC is a (mostly compliant) C compiler.  If you compile a file with an extension of .c instead of .cpp (or anything else), the VC compiler will compile the file as a C file, instead of a C++ file.
0
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
graham_kCommented:
if you really wrote C++, instead of just using a C++ compiler to write C, as many people do, then you have a MAJOR task ahead and one which I doubt can be automated.

Anyone who disagrees can tell me how a simple class can be translated, then we'll take it from there (with interesting things, like the STL).

I'm sure that this is the correct answer - can't be (realistically) done - but I've never seen the bringer of bad news get the points yet :-)

Nietod, Chensu, JKR, Kangaroo ? I'd like to hear what you guys think.
0
 
jhanceCommented:
Why rewrite from C++ to C?  As I said, why not get the freely available C++ compiler for the AIX machine.

I'm assuming that the app in question is a console (or simple UI) program and that most of the porting effort will be to remove the "Window"isms from the code.  While this can be a large enough task as it is, why complicate the job any more than necessary by recoding C++ to C?  In fact, if you're desperate, you could dig up an old copy of the original CFRONT.  Oddly enough, this was how C++ got compiled in the old days.  CFRONT converted C++ to C which was then compiled on the machine's native C compiler.
0
 
nietodCommented:
>> can tell me how a simple class can be translated
The first C++ "compiler" was Bjarne Stroustrup's cfront.  It worked to compile to "standard" C++ code up until about the addition of templates.  It worked by converting C++ code into C code and then calling the C compiler on the resulting code.  In other words, it was a translator, not a true compie.

A class can be translated to be a structure.  The class'es data members become members of the structure.  The class's member function become ordinary functions that take a parameter that is the pointer to the structure they operator on.
0
 
jasonclarkeCommented:
> if you really wrote C++, instead of just using a C++ compiler
> to write C, as many people do, then you have a MAJOR task ahead
> and one which I doubt can be automated.

of course it can be automated.  All the early C++ compilers used to do precisely this (like CFront - as mentioned by jhance).

What should be born in mind though is that the generated 'C' code can only be treated as a 'machine code',  the generated is unlikely to be very human readable, but this does not really matter if you never edit the generated code - i.e. you only edit the C++ source.

Commercial producers of translators exist, and maybe there are free ones available somewhere.  Take a look at this web page:

http://www.edg.com/cpp.html
0
 
nietodCommented:
Opps, jhance pointed that out already.
0
 
graham_kCommented:
hi Nietod, given that you're top dog on this manor, I don't want to stir you up. BUT: that much is obvious and I'm sure that we could all do it manually. There are 2 points, though: 1) CFront, etc. don't include the STL 2) therefore anything fully inclusive of C++ would reuqire a *mjor major* investment to become automatic.

I guess that I write that, not to flame but, because I look to EE for concrete answers while some look on it as a discussion of the finer points of philosophy. If you want that, go to UseNet, if you want answers vome to EE, that's my philosophy.  (damn, I'm begining to regret having started writing this).  

What we really need here is for the original poster to tell us how much of C++ he has actually used, so that we can answer the conversion issue. Or fo rhim to use the GNU C++ compiler for AIX, as  suggested.

Sorry if this rambles or misses the point, but I've just returned from a european luch break which was very liquid & would rather dribble here than hack code :-)
0
 
jasonclarkeCommented:
The translator on the web page that I pointed to above claims to be almost ANSI compliant and to be able to handle the MS dialect of C++, so I don't imagine that the C++ to C translation would be much of a big deal for it.

However, this would require spending money, which is probably not what is wanted.  (I say this because IBMs VisualAge C++ is available both on Windows NT and on AIX,  so compiling with that would probably be a good choice).
0
 
nietodCommented:
>> that much is obvious
Hey, you asked....

overloading, virtual functions, templates exceptions etc can all be handled just as obviously.

>> 1) CFront, etc. don't include the STL
It was abandoned, by Stroustrup, before templates we added.  There is no reason that it could not include templates.

>> 2) therefore anything fully inclusive of C++
>> would reuqire a *mjor major* investment to
>> become automatic.
The level of "investment" wasn't mentioned in your question.  However, writting a Cfront style compiler/translator would be much easier than writting a true compiler.   Whethor you include templates or not has no bearing on that, it would still be easier.
0
 
jasonclarkeCommented:

> It was abandoned, by Stroustrup, before templates we added.
> There is no reason that it could not include templates.

not entirely true.  Certainly until the most recent incarnations the Sun Solaris compiler was CFront based, and it definitely did cope with templates, but not exceptions.

And, the CFront template instantiation mechanism was in some ways more sophisticated than that included with Visual C++.
0
 
nietodCommented:
Yes, but Stroustrup abandoned it. The main problem with the approach is that it is hard to do useful diagnostic reporting.
0
 
jasonclarkeCommented:
My point was just that CFront did do templates,  and as I stated before translators do exist that are as ANSI compliamt as most current C++ compiler.

Also, I believe the KAI C++ compiler (http://www.kai.com/C_plus_plus/), which is one of the most standards compliant, and widely regarded as one of the best optimising C++ compilers works by translating to C and then calling the host platforms C compiler.
0
 
jasonclarkeCommented:
BTW, the KAI compiler is available for AIX too, $1200 per license though ($400 for NT or Linux).
0
 
danbindAuthor Commented:
Uh, thanks for all the responses!  I was out of the office for a while, and as I have a new email address, I wasn't getting any "answer" notifications.  The first answer was really the correct one for my purposes, as I used gpp to build my app, and it works, so, problem solved.  As is often the case, the answer I need doesn't always match the question I ask.   Thanks again!
0

Featured Post

Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

  • 5
  • 5
  • 2
  • +2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now