[fpc-devel] C++ Linking technology

Daniël Mantione daniel.mantione at freepascal.org
Fri Apr 27 11:22:56 CEST 2007



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

> On Fri, 27 Apr 2007, ik wrote:
> =

> > On 4/27/07, Dani=EBl Mantione <daniel.mantione at freepascal.org> 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 cppcl=
ass
> > >> > with only external functions and then add to it it=B4s own methods=
 and
> > >> > fields?
> > >> >
> > >> > If this doesn=B4t exist yet, I would say it would be a good aditio=
n,
> > >> > 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 =3D)
> > >>
> > >> 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++ cla=
ss
> > >> implement a Pascal interface, so it can interoperate with Pascal cod=
e.
> > >>
> > >
> > >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 connecti=
on
> 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=EBl


More information about the fpc-devel mailing list