How to implement C++ class heritage properties in C using C struct?

Discussion in 'C Programming' started by bugzilla, Mar 18, 2005.

  1. bugzilla

    bugzilla Guest

    hi,all,
    I have a C++ program need to convert to c language to be used in a
    emabedded system. the problem is that the original code was writtern
    in C++ language with Parent class and some child class. How can I
    invert these C++ code into pure c code by using struct in C language?

    Can somebody give me any ideas? thanks.

    For example, how to conver the following code into pure c code?

    class PARENT
    {
    public:
    virtual int Init();
    virtual int Add();
    virtual int Sub();
    int Otherfunc();

    private:
    int x;
    int y;
    int z;
    };


    class CHILD1: public PARENT
    {
    public:
    int Init();
    int Add();
    int CHILDOwn();
    privete:
    int a;
    int b;
    int c;
    };

    class CHILD2: public PARENT
    {
    public:
    int Init();
    int Add();
    int Uncle();
    privete:
    int m;
    int n;
    int d;
    };

    PARENT* CreateNewInstance()
    {
    PARENT* pPointer=new CHILD1;
    return pPointer;
    }

    main()
    {
    PARENT * Kids1=CreateNewInstance();
    Kids1->Uncle(); //from children class
    Kids1->Sub(); //from parent class
    Kids1->Otherfunc();//from parent class
    }
     
    bugzilla, Mar 18, 2005
    #1
    1. Advertising

  2. bugzilla

    Guest

    Hi,

    bugzilla wrote:
    > hi,all,
    > I have a C++ program need to convert to c language to be used in a
    > emabedded system. the problem is that the original code was writtern
    > in C++ language with Parent class and some child class. How can I
    > invert these C++ code into pure c code by using struct in C language?
    >
    > Can somebody give me any ideas? thanks.


    A better way is that you write a extern "C" wrapper functions around
    the C++ program, and then compiled both the wrapper and the program
    into a static library.

    Then you will be able to call these functions through pure C code.
    (Of course, you would need to define a header file.)

    > For example, how to conver the following code into pure c code?
    >
    > class PARENT
    > {
    > public:
    > virtual int Init();
    > virtual int Add();
    > virtual int Sub();
    > int Otherfunc();
    >
    > private:
    > int x;
    > int y;
    > int z;
    > };
    >
    >
    > class CHILD1: public PARENT
    > {
    > public:
    > int Init();
    > int Add();
    > int CHILDOwn();
    > privete:
    > int a;
    > int b;
    > int c;
    > };
    >
    > class CHILD2: public PARENT
    > {
    > public:
    > int Init();
    > int Add();
    > int Uncle();
    > privete:
    > int m;
    > int n;
    > int d;
    > };
    >
    > PARENT* CreateNewInstance()
    > {
    > PARENT* pPointer=new CHILD1;
    > return pPointer;
    > }
    >
    > main()
    > {
    > PARENT * Kids1=CreateNewInstance();
    > Kids1->Uncle(); //from children class
    > Kids1->Sub(); //from parent class
    > Kids1->Otherfunc();//from parent class
    > }


    Anyway if your C++ code is not so complex, you can convert
    them into C equivalent. for the code above,
    1. replace class with struct
    2. replace virtual with function pointer
    3. put all parent class members into the child class
    4. write initializing functions for all the struct (class) you use
    and them should return allocated object of that struct (class).
    but it's some complex because you should take care of the
    inheritance.
    5. You may need to write destructor to free all the memory allocated
    by the initializing function.

    Actually, if you want to learn more OO method in C, I think you'd
    better read some books or articles about COM.


    Hanzac
     
    , Mar 18, 2005
    #2
    1. Advertising

  3. In article <>,
    bugzilla <> wrote:
    :I have a C++ program need to convert to c language to be used in a
    :emabedded system. the problem is that the original code was writtern
    :in C++ language with Parent class and some child class. How can I
    :invert these C++ code into pure c code by using struct in C language?

    The early C++ compilers were preprocessors that converted the input
    into C code. If the program to be converted does not use some of the
    more modern C++ constructs, then you might be able to make
    use of that kind of automatic translation.
    --
    Look out, there are llamas!
     
    Walter Roberson, Mar 19, 2005
    #3
  4. bugzilla

    Neil Kurzman Guest

    bugzilla wrote:

    > hi,all,
    > I have a C++ program need to convert to c language to be used in a
    > emabedded system. the problem is that the original code was writtern
    > in C++ language with Parent class and some child class. How can I
    > invert these C++ code into pure c code by using struct in C language?
    >
    > Can somebody give me any ideas? thanks.
    >
    > For example, how to conver the following code into pure c code?
    >
    > class PARENT
    > {
    > public:
    > virtual int Init();
    > virtual int Add();
    > virtual int Sub();
    > int Otherfunc();
    >
    > private:
    > int x;
    > int y;
    > int z;
    > };
    >
    > class CHILD1: public PARENT
    > {
    > public:
    > int Init();
    > int Add();
    > int CHILDOwn();
    > privete:
    > int a;
    > int b;
    > int c;
    > };
    >
    > class CHILD2: public PARENT
    > {
    > public:
    > int Init();
    > int Add();
    > int Uncle();
    > privete:
    > int m;
    > int n;
    > int d;
    > };
    >
    > PARENT* CreateNewInstance()
    > {
    > PARENT* pPointer=new CHILD1;
    > return pPointer;
    > }
    >
    > main()
    > {
    > PARENT * Kids1=CreateNewInstance();
    > Kids1->Uncle(); //from children class
    > Kids1->Sub(); //from parent class
    > Kids1->Otherfunc();//from parent class
    > }


    How embedded? If there is no C++ compiler it usually means a small 8 bit
    CPU. I this if the case rewrite it. there is a reason many 8 bit cpus
    do not have C++ compilers.
     
    Neil Kurzman, Mar 19, 2005
    #4
  5. bugzilla

    Tor Rustad Guest

    "bugzilla" <> wrote in message

    <snip>

    > Can somebody give me any ideas? thanks.
    >
    > For example, how to conver the following code into pure c code?
    >
    > class PARENT
    > {
    > public:
    > virtual int Init();
    > virtual int Add();
    > virtual int Sub();
    > int Otherfunc();
    >
    > private:
    > int x;
    > int y;
    > int z;
    > };


    Alternative 1:
    -----------------

    struct PARENT
    {
    int x, y, z;
    };

    int Init(struct PARENT *);
    int Add(struct PARENT *);
    int Sub(struct PARENT *);
    int Otherfunc(struct PARENT *);


    Alternative 2:
    ------------------

    struct PARENT
    {
    int x, y, z;

    int (*Init) (struct PARENT *);
    int (*Add) (struct PARENT *);
    int (*Sub) (struct PARENT *);
    int (*Otherfunc) (struct PARENT *);
    };

    using function pointers, add more labour, since
    you need to initialilze each function pointer e.g.

    struct PARENT p;

    p.Init = Init();
    p.Add = Add();

    etc.


    > class CHILD1: public PARENT
    > {
    > public:
    > int Init();
    > int Add();
    > int CHILDOwn();
    > privete:
    > int a;
    > int b;
    > int c;
    > };


    int CHILDOwn(struct PARENT *);


    > class CHILD2: public PARENT
    > {
    > public:
    > int Init();
    > int Add();
    > int Uncle();
    > privete:
    > int m;
    > int n;
    > int d;
    > };


    int Uncle(struct PARENT *);

    > PARENT* CreateNewInstance()
    > {
    > PARENT* pPointer=new CHILD1;
    > return pPointer;
    > }


    struct PARENT* New_Parent()
    {
    struct PARENT *p;

    /* what if no memory??? */
    p = malloc( sizeof *p);
    if (p == NULL)
    exit(EXIT_FAILURE);

    /* init members */
    p->x = p->y = p->z = 0;

    /*if using function pointers, init now.. */

    return p;
    }

    > main()
    > {
    > PARENT * Kids1=CreateNewInstance();
    > Kids1->Uncle(); file://from children class
    > Kids1->Sub(); file://from parent class
    > Kids1->Otherfunc();//from parent class
    > }



    int main( void)
    {
    struct PARENT kid = {0};

    Uncle (&kid);
    Sub (&kid);
    Otherfunc (&kid);

    }

    .... or if you want to use PARENT pointer:

    int main( void)
    {
    struct PARENT *pkid = New_Parent();

    Uncle (pkid);
    Sub (pkid);
    Otherfunc (pkid);
    }


    --
    Tor <torust AT online DOT no>
     
    Tor Rustad, Mar 19, 2005
    #5
  6. bugzilla

    bugzilla Guest

    -cnrc.gc.ca (Walter Roberson) wrote in message news:<d1fqt9$rk0$>...
    > In article <>,
    > bugzilla <> wrote:
    > :I have a C++ program need to convert to c language to be used in a
    > :emabedded system. the problem is that the original code was writtern
    > :in C++ language with Parent class and some child class. How can I
    > :invert these C++ code into pure c code by using struct in C language?
    >
    > The early C++ compilers were preprocessors that converted the input
    > into C code. If the program to be converted does not use some of the
    > more modern C++ constructs, then you might be able to make
    > use of that kind of automatic translation.


    Thanks. But where can I find such compiler? can you give me some
    useful link? thanks.
     
    bugzilla, Mar 19, 2005
    #6
  7. bugzilla

    Roger Leigh Guest

    Re: How to implement C++ class heritage properties in C using Cstruct?

    -----BEGIN PGP SIGNED MESSAGE-----
    Hash: SHA1

    (bugzilla) writes:

    > I have a C++ program need to convert to c language to be used in a
    > emabedded system. the problem is that the original code was writtern
    > in C++ language with Parent class and some child class. How can I
    > invert these C++ code into pure c code by using struct in C language?


    http://www.le-hacker.org/papers/gobject/
    http://developer.gnome.org/arch/gtk/object.html
    http://developer.gnome.org/doc/API/2.0/gobject/index.html
    http://www.lore.ua.ac.be/Teaching/Thesis2LIC/2003-2004/Hendrickx.pdf

    (Don't worry about any GNOME bias--GType/GObject is all standard C
    with no dependencies other than GLib and libc.)


    Regards,
    Roger

    - --
    Roger Leigh
    Printing on GNU/Linux? http://gimp-print.sourceforge.net/
    Debian GNU/Linux http://www.debian.org/
    GPG Public Key: 0x25BFB848. Please sign and encrypt your mail.
    -----BEGIN PGP SIGNATURE-----
    Version: GnuPG v1.4.0 (GNU/Linux)
    Comment: Processed by Mailcrypt 3.5.8 <http://mailcrypt.sourceforge.net/>

    iD8DBQFCO/8SVcFcaSW/uEgRAtUhAKDI44R0egs+2ZdcMmSrOaQ/D4wvAQCfad0H
    LSBjlKJ4sSZbU5KqGnCJH2w=
    =P/4V
    -----END PGP SIGNATURE-----
     
    Roger Leigh, Mar 19, 2005
    #7
  8. bugzilla

    Jack Klein Guest

    On 18 Mar 2005 15:55:29 -0800, wrote in comp.lang.c:

    > Hi,
    >
    > bugzilla wrote:
    > > hi,all,
    > > I have a C++ program need to convert to c language to be used in a
    > > emabedded system. the problem is that the original code was writtern
    > > in C++ language with Parent class and some child class. How can I
    > > invert these C++ code into pure c code by using struct in C language?
    > >
    > > Can somebody give me any ideas? thanks.

    >
    > A better way is that you write a extern "C" wrapper functions around
    > the C++ program, and then compiled both the wrapper and the program
    > into a static library.


    Where in the C standard does it define "extern "C" wrapper functions"
    or static libraries? Aside from being way off-topic, do you even
    understand the limitations of the OP's situation?

    > Then you will be able to call these functions through pure C code.
    > (Of course, you would need to define a header file.)


    On an embedded platform that doesn't have a C++ compiler in the first
    place? Regardless of platform, C neither defines, requires, nor
    guarantees interoperability with C++, or any other language for that
    matter.

    [big snip of OP's off-topic C++ code]

    > Anyway if your C++ code is not so complex, you can convert
    > them into C equivalent. for the code above,
    > 1. replace class with struct
    > 2. replace virtual with function pointer
    > 3. put all parent class members into the child class
    > 4. write initializing functions for all the struct (class) you use
    > and them should return allocated object of that struct (class).
    > but it's some complex because you should take care of the
    > inheritance.
    > 5. You may need to write destructor to free all the memory allocated
    > by the initializing function.
    >
    > Actually, if you want to learn more OO method in C, I think you'd
    > better read some books or articles about COM.


    COM is completely off-topic here as well.

    --
    Jack Klein
    Home: http://JK-Technology.Com
    FAQs for
    comp.lang.c http://www.eskimo.com/~scs/C-faq/top.html
    comp.lang.c++ http://www.parashift.com/c -faq-lite/
    alt.comp.lang.learn.c-c++
    http://www.contrib.andrew.cmu.edu/~ajo/docs/FAQ-acllc.html
     
    Jack Klein, Mar 19, 2005
    #8
  9. In article <>,
    bugzilla <> wrote:
    :-cnrc.gc.ca (Walter Roberson) wrote in message news:<d1fqt9$rk0$>...
    :> The early C++ compilers were preprocessors that converted the input
    :> into C code.

    :Thanks. But where can I find such compiler? can you give me some
    :useful link? thanks.

    "AT&T C++ TRANSLATOR" is the best known. This was known as 'cfront'.
    It is possible that the source is available somewhere. Some random links:
    http://www.accu.org/acornsig/public/cathlib/docs/probs.html
    http://compilers.iecc.com/comparch/article/94-11-070 (watch the date!)
    http://homepage.ntlworld.com/thouky/software/cathlibcpp/docs/casts.html

    See also 'Cback',
    http://www.faqs.org/faqs/C -faq/libraries/part4/



    There were others, many essentially derivatives of cfront:

    HP's C++ with the -F option, http://docs.hp.com/en/92501-90029/ch03s02.html
    and SGI's C++ Translator http://techpubs.sgi.com
    http://www.risc.uni-linz.ac.at/education/courses/ws2003/intropar/origin-new/CC_PG/sgi_html/apb.html
    Sun had one as well.

    I suspect KAI's C++ might be the obscure non-cfront that the iecc article
    refered to. I haven't heard of KAI (Kuck and Associates) for a long time...
    http://zampano.zam.kfa-juelich.de/software/kccdoc/v4.0/doc/migrate/
    --
    This signature intentionally left... Oh, darn!
     
    Walter Roberson, Mar 19, 2005
    #9
  10. bugzilla

    Hanzac Chen Guest

    Hi, Jack

    Jack Klein wrote:
    > Where in the C standard does it define "extern "C" wrapper functions"
    > or static libraries? Aside from being way off-topic, do you even
    > understand the limitations of the OP's situation?


    Are they related to the C standard or related to the code generator
    and the linker? AS for the OP's situation, I know that if using OP
    it will need a considerable backend runtime library. But if it's a
    big CPP project, and you want to use it in a C project, will you still
    want to convert its CPP code into C? Are there any automatic tools
    available and they won't bring any trouble?

    > > Then you will be able to call these functions through pure C code.
    > > (Of course, you would need to define a header file.)

    >
    > On an embedded platform that doesn't have a C++ compiler in the first
    > place? Regardless of platform, C neither defines, requires, nor
    > guarantees interoperability with C++, or any other language for that
    > matter.


    Doesn't GCC support most of the modern CPUs? I think it's quite good
    for developing on an embedded platform.

    Why do you just see things literally? actually C compiler is always
    being implemented powerful enough to be able to do most of the tasks.
    So however the C++ code is generated, as long as it's not virtual and
    can run on a real machine, it should be able to be accessed by C code.

    > COM is completely off-topic here as well.


    I think as COM (Component Object Model) is language free and C can also
    access COM interfaces and implement them, there are articles and
    techniques out there. OK, I see GObject is also mentioned, so it might
    be a better choice.

    I don't mean to argue with you, it's just IMHO, and I'm not quite
    familiar with CPP 'cause I tend to use C and prefer C.

    Hanzac
     
    Hanzac Chen, Mar 20, 2005
    #10
  11. bugzilla

    Greg Comeau Guest

    In article <>,
    <> wrote:
    >bugzilla wrote:
    >> hi,all,
    >> I have a C++ program need to convert to c language to be used in a
    >> emabedded system. the problem is that the original code was writtern
    >> in C++ language with Parent class and some child class. How can I
    >> invert these C++ code into pure c code by using struct in C language?
    >>
    >> Can somebody give me any ideas? thanks.

    >
    >A better way is that you write a extern "C" wrapper functions around
    >the C++ program, and then compiled both the wrapper and the program
    >into a static library.


    Assuming the OP wants to do this because s/he doesn't have
    a C++ compiler, that clearly won't work.

    >Then you will be able to call these functions through pure C code.
    >(Of course, you would need to define a header file.)


    And probably need to deal with a whole bunch of other
    non-obvious ways of doing things.

    >Anyway if your C++ code is not so complex, you can convert
    >them into C equivalent. for the code above,
    >1. replace class with struct
    >2. replace virtual with function pointer
    >3. put all parent class members into the child class
    >4. write initializing functions for all the struct (class) you use
    > and them should return allocated object of that struct (class).
    > but it's some complex because you should take care of the
    > inheritance.
    >5. You may need to write destructor to free all the memory allocated
    > by the initializing function.
    >
    >Actually, if you want to learn more OO method in C, I think you'd
    >better read some books or articles about COM.


    Yes, things like this would need to be done.
    But as with any hand conversion, is error prone, tedious,
    and as you note, may depend upon whether the C++ code is
    complex or not (for some definition of "complex").
    This also does not deal with any room for dealing with
    idioms, design, etc.
    --
    Greg Comeau / Comeau for the Mac? Stay tuned.
    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?
     
    Greg Comeau, Mar 28, 2005
    #11
  12. bugzilla

    Greg Comeau Guest

    In article <d1fqt9$rk0$>,
    Walter Roberson <-cnrc.gc.ca> wrote:
    >In article <>,
    >bugzilla <> wrote:
    >:I have a C++ program need to convert to c language to be used in a
    >:emabedded system. the problem is that the original code was writtern
    >:in C++ language with Parent class and some child class. How can I
    >:invert these C++ code into pure c code by using struct in C language?
    >
    >The early C++ compilers were preprocessors that converted the input
    >into C code.


    Early versions of Comeau C++ were based upon cfront.
    Early C++ compilers were no more preprocessors than any compiler is.
    Early C++ _compilers_ were... well, compilers :)

    >If the program to be converted does not use some of the
    >more modern C++ constructs, then you might be able to make
    >use of that kind of automatic translation.


    Actually, the most compliant C++ compiler and most modern C++ compiler
    makes use of such automatic translations, and hence also allows
    very modern C++ constructs. Modern versions of Comeau C++ are
    still integrated to do this, though they no longer are cfront based.
    --
    Greg Comeau / Comeau for the Mac? Stay tuned.
    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?
     
    Greg Comeau, Mar 28, 2005
    #12
  13. bugzilla

    Greg Comeau Guest

    In article <>,
    bugzilla <> wrote:
    >-cnrc.gc.ca (Walter Roberson) wrote in message news:<d1fqt9$rk0$>...
    >> In article <>,
    >> bugzilla <> wrote:
    >> :I have a C++ program need to convert to c language to be used in a
    >> :emabedded system. the problem is that the original code was writtern
    >> :in C++ language with Parent class and some child class. How can I
    >> :invert these C++ code into pure c code by using struct in C language?


    Why do you want to do this? Because there is no C++ compiler available?

    >> The early C++ compilers were preprocessors that converted the input
    >> into C code. If the program to be converted does not use some of the
    >> more modern C++ constructs, then you might be able to make
    >> use of that kind of automatic translation.

    >
    >Thanks. But where can I find such compiler? can you give me some
    >useful link? thanks.


    http://www.comeaucomputing.com But do note that you are probably
    seeking customizations in order to obtain a C++ compiler, and so
    should probably email us.
    --
    Greg Comeau / Comeau for the Mac? Stay tuned.
    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?
     
    Greg Comeau, Mar 28, 2005
    #13
  14. bugzilla

    Greg Comeau Guest

    In article <>,
    Jack Klein <> wrote:
    >On 18 Mar 2005 15:55:29 -0800, wrote in comp.lang.c:
    >> bugzilla wrote:
    >> > I have a C++ program need to convert to c language to be used in a
    >> > emabedded system. the problem is that the original code was writtern
    >> > in C++ language with Parent class and some child class. How can I
    >> > invert these C++ code into pure c code by using struct in C language?
    >> >
    >> > Can somebody give me any ideas? thanks.

    >>
    >> A better way is that you write a extern "C" wrapper functions around
    >> the C++ program, and then compiled both the wrapper and the program
    >> into a static library.

    >
    >Where in the C standard does it define "extern "C" wrapper functions"
    >or static libraries? Aside from being way off-topic, do you even
    >understand the limitations of the OP's situation?
    >
    >> Then you will be able to call these functions through pure C code.
    >> (Of course, you would need to define a header file.)

    >
    >On an embedded platform that doesn't have a C++ compiler in the first
    >place?


    Good points.

    >Regardless of platform, C neither defines, requires, nor
    >guarantees interoperability with C++, or any other language for that
    >matter.


    Though on a practical matter, it's often possible to have your
    cake and eat it too. That is to say, the interoperatability can
    often be achieved, though not as the poster is saying, and often
    with limitations, and at a loss of things like portability.
    But then, that's often a given and even desirable given the
    nature of the beast.
    --
    Greg Comeau / Comeau for the Mac? Stay tuned.
    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?
     
    Greg Comeau, Mar 28, 2005
    #14
  15. bugzilla

    Greg Comeau Guest

    In article <d1hte3$l88$>,
    Walter Roberson <-cnrc.gc.ca> wrote:
    >In article <>,
    >bugzilla <> wrote:
    >:-cnrc.gc.ca (Walter Roberson) wrote in message news:<d1fqt9$rk0$>...
    >:> The early C++ compilers were preprocessors that converted the input
    >:> into C code.
    >
    >:Thanks. But where can I find such compiler? can you give me some
    >:useful link? thanks.
    >
    >"AT&T C++ TRANSLATOR" is the best known. This was known as 'cfront'.
    >...


    But also limited, defunct and extremely outdated at this point.

    >I suspect KAI's C++ might be the obscure non-cfront that the iecc article
    >refered to. I haven't heard of KAI (Kuck and Associates) for a long time...
    >http://zampano.zam.kfa-juelich.de/software/kccdoc/v4.0/doc/migrate/


    Yes, KAI and it's compiler no longer exist as such.
    As to "obscure non-cfront", I guess call it whatever you want
    (Stroustrup has called it "son of cfront" FYI), but it still
    fills needs. If it didn't, Comeau Computing wouldn't exist,
    at least not in our current form.
    --
    Greg Comeau / Comeau for the Mac? Stay tuned.
    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?
     
    Greg Comeau, Mar 28, 2005
    #15
  16. bugzilla

    Greg Comeau Guest

    In article <>,
    Hanzac Chen <> wrote:
    >Jack Klein wrote:
    >> Where in the C standard does it define "extern "C" wrapper functions"
    >> or static libraries? Aside from being way off-topic, do you even
    >> understand the limitations of the OP's situation?

    >
    >Are they related to the C standard or related to the code generator
    >and the linker?


    Not as such. The Standard talks about things which need to get done,
    so it won't talk of static libraries themselves (or other kinds)
    just that resolution of names should occur, and so on. And of course
    it doesn't know anything about extern "C". Of course, both the
    C++ and C standard are setup so that there is fighting changes
    across compilers and even languages, but it can only go so far,
    and there are no guarantees. So lots is left to vendors to get
    going (or not) in specific implementations.

    > AS for the OP's situation, I know that if using OP
    >it will need a considerable backend runtime library. But if it's a
    >big CPP project, and you want to use it in a C project, will you still
    >want to convert its CPP code into C?


    There is no requirement that cross language interoperability needs
    for C++ to be converted to C. As as Jack pointed out it's beyond
    the realm of the standard(s). So it's left to what vendors,
    users, etc can get going.

    >Are there any automatic tools available


    Comeau C++, after purposeful customization since it needs to
    deal with plaform specific issues, as would any such tool.

    >and they won't bring any trouble?


    As with any compiler, not if done right, and done within the realm
    of the culture of the platform. IOWs, what was just said, as the
    standards don't offer any guarantees, etc, and also certain platforms
    have their own limitations and sensibilities.

    >actually C compiler is always
    >being implemented powerful enough to be able to do most of the tasks.
    >So however the C++ code is generated, as long as it's not virtual and
    >can run on a real machine, it should be able to be accessed by C code.


    It certainly possible in many cases, but it's "never" as simple as
    just compiling it and linking it. Very far from that.
    --
    Greg Comeau / Comeau for the Mac? Stay tuned.
    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?
     
    Greg Comeau, Mar 28, 2005
    #16
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. marco

    dynamic import with heritage

    marco, Jun 10, 2004, in forum: Python
    Replies:
    8
    Views:
    598
    marco
    Jun 11, 2004
  2. Zero
    Replies:
    8
    Views:
    509
  3. Alexandre Badez

    Multi Heritage with slots

    Alexandre Badez, Sep 5, 2007, in forum: Python
    Replies:
    5
    Views:
    257
    Alexandre Badez
    Sep 5, 2007
  4. John Pritchard-williams

    Japanese Heritage of Ruby: useful by-product?....

    John Pritchard-williams, Aug 28, 2008, in forum: Ruby
    Replies:
    4
    Views:
    141
    Dido Sevilla
    Aug 29, 2008
  5. Vincent M.

    Troubles with objects heritage.

    Vincent M., Apr 27, 2004, in forum: Javascript
    Replies:
    1
    Views:
    84
    Michael Winter
    May 3, 2004
Loading...

Share This Page