Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

How to convert C++ to C code?

Status
Not open for further replies.

anumuttu

Newbie level 5
Joined
Aug 22, 2007
Messages
8
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,336
Hi pals,

can anybody knows how to convert "C++" [.cc or .cpp] codes to "C" [.c] files??????

I was just wondering how you would implement this into C if it actually is possible, if not, how do you

guys implement an equal way of dealing with this in C ?

For instance, if you would have classes like this in C++:

class Lightwave
{
Public:// BLA BLA
private:// BLA BLA

...
};

class Modeler : public Lightwave
{
Public:// BLA BLA
private:// BLA BLA
...
};

class Layout : public Lightwave
{
Public:// BLA BLA
private:// BLA BLA
...
};

int main()
{
cout << "Press enter to exit.\n";;

cin.ignore(cin.rdbuf()->in_avail() + 1);

return 0;
}
 

Re: C++ to C conversion

C has no the concept of herency. So you can code this in C as you know. You have to change the way of think from Object Oriented in C++ to Structural in C.

A similar approach in C could be:

Place all the public and private functions in a file called LIGHTWARE.C.
the private functions in C++ can be static in the .c in order to be private.
the public functions in C++ should be declared in LIGHTWARE.H.

If class Layout methods are completely different from LightWare the use. LAYOUT.c with their implementation.

If they are similar in class Layout you can call LIGHTWARE functions in a layered approach.

I hope it helps.
 

C++ to C conversion

You cannot directly convert it into C. You will have to do a little workaround.

Convert classes into structures. And accordingly modify functions.
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top