C++ code to C code

Can you tell me how to convert the Base class,Derived class(inheritance property)in C code without ignoring the idea of inheritance property in C?
Also can you give any suggestions on how to handle the Public,Private,Protected functions of a class in C,how should i port them
gaatriAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

WynCommented:
you'd better not convert it.
Regards
Wyn
0
LDCCommented:
You should look for the original C++ preprocessor, which translated C++ into C.
0
KangaRooCommented:
That is difficult indeed. I have seen C code using structures with a function pointer. This would provide the basics of virtual members.
Originally, I think, C++ was implemented, by AT&T, as a macro (?) front end which produced ordinary C code.
0
Cloud Class® Course: Microsoft Azure 2017

Azure has a changed a lot since it was originally introduce by adding new services and features. Do you know everything you need to about Azure? This course will teach you about the Azure App Service, monitoring and application insights, DevOps, and Team Services.

nietodCommented:
>> look for the original C++ preprocessor

>> I think, C++ was implemented, by AT&T, as
>> a macro (?) front end
Bjarne stroustrup wrote the first C++ compiler called "Cfront" as a source code "pre-processor" that converted the C++ code into C code that could be compiled to produce the application.  He mantained it for many years and the source code was avaialble to the public.  However, he didn't support it in recent years so his copy would not support recent changes, like exception, templates, namespaces etc.  

Anyways C can represent a derived class as a structure that has the bease class has its first member, like

****C++*****

class Base
{
   int i;
};

class Derived : public Base
{
    char ch;
};

******C******
typedef struct
{
    int i;
} Base;

typedef struct
{
   Base b;
   char ch;
} Derived;


Now that allows you to perform the same sort of functionallity of C++'s inheriticance in C.  That does not mean that those C structurees are in any way compatible with a C++ class.

Obviously there is no way to handle private and protected in C.  You have to make sure no to "touch" members when you don't have access to them.  If you use a pre-processor program like "cfront", it woudl not generate code to access an private member when inappropriate.  
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
nietodCommented:
Opps, that was meant to be acomment.  Sorry.

Well, its for 5 pts, I guess no one will be too mad at me.  :-)
0
ArvindtnCommented:
I don't know whether namespace works in C, but if it could be used in C, then i think we can create a round about way to implement private and protected member datas using Namespaces. somebody please Correct me if iam wrong
0
nietodCommented:
C didn't originally support namspaces, although when the C++ standard was created a C standard was also created and they did addopt a few extra features from C++, but I think this was all little things, like use of constants.  So I really doubt that C supports namespaces.  
0
sisuCommented:
Hi,
  In pure C compiler U don't get any sort of oop's concepts. If Ur working in c++ environment then only U get these features.

   
0
KangaRooCommented:
I don't agree. OOP programming is, as you say, a concept. You can follow this concept even in C. And you can break it in C++. OOP programming is not a language, it is a way to solve programming problems.
0
nietodCommented:
I agree with kangaroo.  The proof being the fact that early C++ compilers, like Cfront converted C++ code into C code.  Since the C++ code was OO, the C code was too.  It was just ugly to look at.
0
ozoCommented:
ugly to maintain too
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C++

From novice to tech pro — start learning today.