Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-devel / 2007-04

C++ Linking technology

10 messages · 7 people ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Felipe Monteiro de Carvalho

Hallo,

Another day Florian was talking about the cppclass, a experimental feature to link to c++

I would like to know: Could someone inherit a class based on cppclass with only external functions and then add to it it´s own methods and fields?

If this doesn´t exist yet, I would say it would be a good adition, because then one can use the c++ classes like they are often used on c++ app: By inheriting them and adding your own code.

This is a very specific question, so I could just ask Florian directly, but I guess that here everyone will have access to the answer =)

thanks a lot,

Felipe Monteiro de Carvalho

Reply by email

Daniël Mantione
to Felipe Monteiro de Carvalho

Op Fri, 27 Apr 2007, schreef Felipe Monteiro de Carvalho:

Show quoted text 16 lines
Hallo, Another day Florian was talking about the cppclass, a experimental feature to link to c++ I would like to know: Could someone inherit a class based on cppclass with only external functions and then add to it it´s own methods and fields? If this doesn´t exist yet, I would say it would be a good adition, because then one can use the c++ classes like they are often used on c++ app: By inheriting them and adding your own code. This is a very specific question, so I could just ask Florian directly, but I guess that here everyone will have access to the answer =)

To be able to support such a thing you would have to implement all features of C++ objects into Pascal, effectively turning Pascal into C++ with a different syntax. The proper way would be to have the C++ class implement a Pascal interface, so it can interoperate with Pascal code.

Daniël

Reply by email

ik
to Daniël Mantione
Daniël Mantione wrote 26 lines
Op Fri, 27 Apr 2007, schreef Felipe Monteiro de Carvalho: > Hallo, > > Another day Florian was talking about the cppclass, a experimental > feature to link to c++ > > I would like to know: Could someone inherit a class based on cppclass > with only external functions and then add to it it´s own methods and > fields? > > If this doesn´t exist yet, I would say it would be a good adition, > because then one can use the c++ classes like they are often used on > c++ app: By inheriting them and adding your own code. > > This is a very specific question, so I could just ask Florian > directly, but I guess that here everyone will have access to the > answer =) To be able to support such a thing you would have to implement all features of C++ objects into Pascal, effectively turning Pascal into C++ with a different syntax. The proper way would be to have the C++ class implement a Pascal interface, so it can interoperate with Pascal code.

How does other languages such as Perl/Ruby/Python (for example) etc, handle such connections ?

Daniël

Ido

Reply by email

Michael Van Canneyt
to ik
ik wrote 30 lines
On 4/27/07, Daniël Mantione wrote: > >> >> Op Fri, 27 Apr 2007, schreef Felipe Monteiro de Carvalho: >> >> > Hallo, >> > >> > Another day Florian was talking about the cppclass, a experimental >> > feature to link to c++ >> > >> > I would like to know: Could someone inherit a class based on cppclass >> > with only external functions and then add to it it´s own methods and >> > fields? >> > >> > If this doesn´t exist yet, I would say it would be a good adition, >> > because then one can use the c++ classes like they are often used on >> > c++ app: By inheriting them and adding your own code. >> > >> > This is a very specific question, so I could just ask Florian >> > directly, but I guess that here everyone will have access to the >> > answer =) >> >> To be able to support such a thing you would have to implement all >> features of C++ objects into Pascal, effectively turning Pascal into C++ >> with a different syntax. The proper way would be to have the C++ class >> implement a Pascal interface, so it can interoperate with Pascal code. >> > >How does other languages such as Perl/Ruby/Python (for example) etc, >handle such connections ?

They don't have to: the compilers/interpreters for these languages are written in C. All they need to do in the worst case is compile a small stub. For Pascal, the situation is not so simple, as there is no connection with C whatsoever.

Michael

Reply by email

Daniël Mantione
to ik: How does other languages such as Perl/Ruby/Python (for example) etc, handle such…

Op Fri, 27 Apr 2007, schreef ik:

Show quoted text 8 lines
> > To be able to support such a thing you would have to implement all > > features of C++ objects into Pascal, effectively turning Pascal into C++ > > with a different syntax. The proper way would be to have the C++ class > > implement a Pascal interface, so it can interoperate with Pascal code. > > > > How does other languages such as Perl/Ruby/Python (for example) etc, > handle such connections ?

Perl and Python cannot access C++ directly. I don't know about Ruby.

Daniël

Reply by email

Daniël Mantione
to Michael Van Canneyt: They don't have to: the compilers/interpreters for these languages are written in C. All…

Op Fri, 27 Apr 2007, schreef Michael Van Canneyt:

Show quoted text 37 lines
On Fri, 27 Apr 2007, ik wrote: > On 4/27/07, Daniël Mantione wrote: > > > >> > >> Op Fri, 27 Apr 2007, schreef Felipe Monteiro de Carvalho: > >> > >> > Hallo, > >> > > >> > Another day Florian was talking about the cppclass, a experimental > >> > feature to link to c++ > >> > > >> > I would like to know: Could someone inherit a class based on cppclass > >> > with only external functions and then add to it it´s own methods and > >> > fields? > >> > > >> > If this doesn´t exist yet, I would say it would be a good adition, > >> > because then one can use the c++ classes like they are often used on > >> > c++ app: By inheriting them and adding your own code. > >> > > >> > This is a very specific question, so I could just ask Florian > >> > directly, but I guess that here everyone will have access to the > >> > answer =) > >> > >> To be able to support such a thing you would have to implement all > >> features of C++ objects into Pascal, effectively turning Pascal into C++ > >> with a different syntax. The proper way would be to have the C++ class > >> implement a Pascal interface, so it can interoperate with Pascal code. > >> > > > >How does other languages such as Perl/Ruby/Python (for example) etc, > >handle such connections ? They don't have to: the compilers/interpreters for these languages are written in C. All they need to do in the worst case is compile a small stub. For Pascal, the situation is not so simple, as there is no connection with C whatsoever.

Some examples:

* C++ constructors do not have a name. Deriving and enhancing C++ classes in Pascal would mean you would have to add syntax to write nameless constructors, and syntax to call a constructor without mentioning its name.

* The copy constructor is a very central theme in C++ OOP programming. Being able to derive from C++ classes would mean you would have to be able to write a copy constructor in Pascal, and would modify the semantics of an assignment to call the copy constructor.

To my knowledge, no language has gone this path. Perl, Python all have their own OOP classes and deal with C++ only through wrappers.

Daniël

Reply by email

Florian Klaempfl
to Felipe Monteiro de Carvalho: Another day Florian was talking about the cppclass, a experimental feature to link to c++…
Show quoted text 8 lines
Hallo, Another day Florian was talking about the cppclass, a experimental feature to link to c++ I would like to know: Could someone inherit a class based on cppclass with only external functions and then add to it it´s own methods and fields?

No, because this really complicates things. C++ like vmt generation, contructor/destructor handling etc.

If this doesn´t exist yet, I would say it would be a good adition,

This is no addition but complicating things by 10 :)

Show quoted text 8 lines
because then one can use the c++ classes like they are often used on c++ app: By inheriting them and adding your own code. This is a very specific question, so I could just ask Florian directly, but I guess that here everyone will have access to the answer =) thanks a lot,

Reply by email

Felipe Monteiro de Carvalho
to Florian Klaempfl
Florian Klaempfl wrote
No, because this really complicates things. C++ like vmt generation, contructor/destructor handling etc.

Ah, ok. thanks. I guess I didn´t know exactly how the cppclass worked.

Felipe Monteiro de Carvalho

Reply by email

peter green
to Michael Van Canneyt: They don't have to: the compilers/interpreters for these languages are written in C. All…
Show quoted text 5 lines
They don't have to: the compilers/interpreters for these languages are written in C. All they need to do in the worst case is compile a small stub. For Pascal, the situation is not so simple, as there is no connection with C whatsoever.

well there is nothing to stop you writing stubs in C/C++ to use with your pascal application, i don't see how thats any harder than writing a C++ stub to call from a plain C interpreter.

C++ on linux is a bit of a nightmare though with libstdc++ changing ABI all the time and apps linked against multiple versions of libstdc++ tending to crash so C++ code in your app may be something you want to avoid.

you could possiblly ship the c++ as source and the pascal as .o files avoiding the need for fpc on the users machine while avoiding the libstdc++ versioning issues.

Reply by email