f



c++ to c

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()
    {
    }
};

0
2/6/2006 9:02:35 PM
comp.lang.c++ 49423 articles. 7 followers. Post Follow

13 Replies
959 Views

Similar Articles

[PageSpeed] 56

oops, I mean from C++ to C

0
2/6/2006 9:06:21 PM
jamihuq wrote:
> 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.

See this FAQ:

http://www.parashift.com/c++-faq-lite/compiler-dependencies.html#faq-38.13

Cheers! --M

0
mlimber (2146)
2/6/2006 9:30:08 PM
jamihuq wrote:
> 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...

-- 
Ian Collins.
0
ian-news (10155)
2/6/2006 9:44:53 PM
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

0
2/6/2006 10:18:59 PM
jamihuq wrote:
> 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.

-- 
Ian Collins.
0
ian-news (10155)
2/6/2006 11:08:34 PM
The following article should help:

http://www.eventhelix.com/RealtimeMantra/Basics/object_oriented_programming_in_c.htm

--
EventStudio System Designer 2.5 - http://www.EventHelix.com/EventStudio
Sequence Diagram Based System Design and Object Interaction Modeling
Tool

0
eventhelix (355)
2/7/2006 4:02:25 AM
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.

0
2/7/2006 4:46:43 AM
In article <1139259755.280485.281220@g47g2000cwa.googlegroups.com>,
jamihuq <jamihuq2002@yahoo.com> wrote:
>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.
-- 
Greg Comeau /     Celebrating 20 years of Comeauity!
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?
0
comeau (830)
2/7/2006 6:15:17 AM
In article <1139287603.082810.202100@g43g2000cwa.googlegroups.com>,
Wormald <ianfinlay_jobs@yahoo.com.au> wrote:
>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.
-- 
Greg Comeau /     Celebrating 20 years of Comeauity!
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?
0
comeau (830)
2/7/2006 6:20:57 AM
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.

0
2/8/2006 3:59:24 PM
jamihuq wrote:
> 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.

--
EventStudio System Designer 2.5 - http://www.EventHelix.com/EventStudio
Sequence Diagram Based System Design and Object Interaction Modeling
Tool

0
eventhelix (355)
2/9/2006 12:33:20 PM
In article <1139281496.130541.111630@g44g2000cwa.googlegroups.com>,
EventHelix.com <eventhelix@gmail.com> wrote:
>The following article should help:
>
>http://www.eventhelix.com/RealtimeMantra/Basics/object_oriented_programming_in_c.htm

Unfortunately, the article does not not necessarily discuss
object oriented programming in C.  It does reflect some mapping
that is possible, but not necessarily desired even in a C version.
-- 
Greg Comeau /     Celebrating 20 years of Comeauity!
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?
0
comeau (830)
2/9/2006 1:53:43 PM
In article <1139488399.981789.10390@g43g2000cwa.googlegroups.com>,
EventHelix.com <eventhelix@gmail.com> wrote:
>jamihuq wrote:
>> 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.

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.
-- 
Greg Comeau /     Celebrating 20 years of Comeauity!
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?
0
comeau (830)
2/9/2006 2:00:13 PM
Reply: