c++ to c

J

jamihuq

Hello Everyone,
I have a project where I need to write C++ code in C (due to OS
issues). Can someone please show me exactly what I need to do to
convert the code to C.

Thanks
Jami

Here is the code I need to convert to C++:
class CTestSuite : public CTestSuiteBase
{
public :
CTestSuite(CTestBase *aTest);
virtual ~CTestSuite();

virtual TInt InvokeTestL(int argc, char * argv[], TTestConfig *
aConfig) ;

IMPORT_C CTestSuite *GetTestSuite();


virtual int RunTestL(int aArgc, char *aArgv [], TTestConfig
*aConfig);

protected:
CTestBase *iTest;
} ;

class CTestSuiteBase : public CBase
{
public :
virtual TInt InvokeTestL(int aArgc,
char *aArgv [],
TTestConfig *aConfig) = 0;
} ;


class CTestBase : public CBase
{
public :
virtual TInt InitializeL (int argc, char * argv[],
TTestConfig * aConfig) = 0 ;
virtual TInt RunTestL (int argc, char * argv[]) = 0 ;
virtual TInt Cleanup () = 0 ;
} ;

class CBase
{
public:
CBase()
{
}
virtual ~CBase()
{
}
};
 
I

Ian Collins

jamihuq said:
Hello Everyone,
I have a project where I need to write C++ code in C (due to OS
issues). Can someone please show me exactly what I need to do to
convert the code to C.
You realy need a Cfront compiler, if you can find one.
www.comeaucomputing.com may be a good option.

Otherwise, start from scratch...
 
J

jamihuq

Thanks for the replies. I have already gone to those sites, but I
believe I need to start from scratch. Can someone show me the basic
structure of the code and I think I can take it from there.

Thanks
Jami
 
I

Ian Collins

jamihuq said:
Thanks for the replies. I have already gone to those sites, but I
believe I need to start from scratch. Can someone show me the basic
structure of the code and I think I can take it from there.
Please quote some context.

You should go back to the original requirements and rethink the problem
form a C perspective.

C and C++ are different languages and it's not a good idea to convert
C++ code to C without reevaluating the problem.
 
W

Wormald

I have a similar issue on a legacy system with a mix of C++ C and ASm
source.

The Domain 2.1.0 Cfront C++ compiler (runs on the Apollo workstations
does the job you want). Problem is there aren't too many around these
days. The C source it produces isnt too readable but once you get the
syntax you should be fine.

I currently out source this translation work to a sub contractor in the
USA (he isn't free) Our Apollo;'s died some time ago. but I can put
you in touch with him.

On the Comeau side, I recently received a qoute for a cfront
"tailoring" of comeau C++ at $25K USD, as their present compiler does
not do a "to C" translation (even though it uses a CFRONT front end.
 
G

Greg Comeau

Hello Everyone,
I have a project where I need to write C++ code in C (due to OS
issues).

What issues does the OS have that prohibits C++?
Can someone please show me exactly what I need to do to
convert the code to C.

Not sure what you're asking. If you have a specific and
very very small code sample (as you provided) that can probably
have some thing said about it, but generally speaking, there is
no simple rules per se that can be spelled out.

On another avenue of approach, we (Comeau Computing) do
port of Comeau C++ to new platforms, however, that depends
among other things on first point above.
 
G

Greg Comeau

I have a similar issue on a legacy system with a mix of C++ C and ASm
source.

The Domain 2.1.0 Cfront C++ compiler (runs on the Apollo workstations
does the job you want). Problem is there aren't too many around these
days. The C source it produces isnt too readable but once you get the
syntax you should be fine.

I currently out source this translation work to a sub contractor in the
USA (he isn't free) Our Apollo;'s died some time ago. but I can put
you in touch with him.

On the Comeau side, I recently received a qoute for a cfront
"tailoring" of comeau C++ at $25K USD, as their present compiler does
not do a "to C" translation (even though it uses a CFRONT front end.

Early versions of Comeau C++ were based upon cfront, but that has not
been so for some time (maybe 10 years). Comeau C++ does compile to C,
however, it is normally considered an internal phase of translation
as there is usually nothing of practical use in just the translation
itself, that is, it needs to be useful for a specific platforms,
the front end and tools need to be tailored for a the platform,
it needs accompanying RTL, template instantiation, etc. This is
(well, was) true of cfront itself too.
 
J

jamihuq

Thanks to all, but the EventHelix article actually explained exactly
how I needed to implement my classes and virtual functions. Anyone
wanting to know how C implements virtual functions and derived classes
should read this article.
Again, thanks for the great article.
 
E

EventHelix.com

jamihuq said:
Thanks to all, but the EventHelix article actually explained exactly
how I needed to implement my classes and virtual functions. Anyone
wanting to know how C implements virtual functions and derived classes
should read this article.
Again, thanks for the great article.

Thanks for your kind words. The following articles might also interest
you:

http://www.eventhelix.com/RealtimeMantra/basics/ComparingCPPAndCPerformance.htm

http://www.eventhelix.com/RealtimeMantra/basics/ComparingCPPAndCPerformance2.htm

These articles describe the mapping with C++ constructs and C.
 
G

Greg Comeau

Thanks for your kind words. The following articles might also interest
you:

http://www.eventhelix.com/RealtimeMantra/basics/ComparingCPPAndCPerformance.htm

http://www.eventhelix.com/RealtimeMantra/basics/ComparingCPPAndCPerformance2.htm

These articles describe the mapping with C++ constructs and C.

It seems to me out of the dozen or so points brought up in the articles
that 1/2 of them are incomplete and/or mention something erroneous.
But the executive summary, that often the comparison is close, is on
the money, which is often contrary to ESP et al mantra.
 

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,432
Messages
2,571,680
Members
48,796
Latest member
Greg L.

Latest Threads

Top