Thread View: comp.lang.eiffel
2 messages
2 total messages
Started by Paul Des Rivieres
Wed, 20 Dec 1995 18:22
Calling C++ from C/Eiffel
Author: Paul Des Rivieres
Date: Wed, 20 Dec 1995 18:22
Date: Wed, 20 Dec 1995 18:22
36 lines
1922 bytes
1922 bytes
During the summer I contacted ISE support staff about how to call
C++ from Eiffel. They responsed that it was impossible because
there was no way to call the C++ constructor. Since I have a C++
class interface to a mission critical C++ application one of my
co-workers researched and found a solution. Add the following
routines to the C++ class:
ClassName * ClassName::init_object (void)
{
ClassName *cp;
if (!(cp = (ClassName *) malloc(sizeof(ClassName))))
return NULL;
*cp = ClassName();
return cp;
}
void ClassName::free_object (ClassName *cp)
{
free(cp);
}
Then compile the C++ class keeping the interm C file (use +i for
the CenterLine compiler). Make note of the names of the C routines
corresponding to the C++ routines. In C/Eiffel call the C routine
corresponding to ClassName::init_object then for the original C++
routines call the corresponding C routines with ClassName *cp as the
first parameter.
Note: In Eiffel it is possible to have ClassName::free_object called
with the object is garbage collected; inherit from MEMORY add redefine
dispose to call ClassName::free_object (note: use C version's name).
---------------------------------------------------------------
Paul Des Rivieres Senior Computer Analyst/Programmer
Communications Security Establishment, Govt of Canada, Ottawa
pdesrivi@cse.dnd.ca Voice: (613)991-8796 Fax: (613)991-8811
Re: Calling C++ from C/Eiffel
Author: vlad
Date: Sun, 24 Dec 1995 22:50
Date: Sun, 24 Dec 1995 22:50
44 lines
2027 bytes
2027 bytes
Paul Des Rivieres <pdesrivi@cse.dnd.ca> wrote:
>During the summer I contacted ISE support staff about how to call
>C++ from Eiffel. They responsed that it was impossible because
>there was no way to call the C++ constructor. Since I have a C++
>class interface to a mission critical C++ application one of my
>co-workers researched and found a solution. Add the following
>routines to the C++ class:
>ClassName * ClassName::init_object (void)
>{
> ClassName *cp;
> if (!(cp = (ClassName *) malloc(sizeof(ClassName))))
> return NULL;
> *cp = ClassName();
> return cp;
>}
>void ClassName::free_object (ClassName *cp)
>{
> free(cp);
>}
>Then compile the C++ class keeping the interm C file (use +i for
>the CenterLine compiler). Make note of the names of the C routines
>corresponding to the C++ routines. In C/Eiffel call the C routine
>corresponding to ClassName::init_object then for the original C++
>routines call the corresponding C routines with ClassName *cp as the
>first parameter.
>Note: In Eiffel it is possible to have ClassName::free_object called
>with the object is garbage collected; inherit from MEMORY add redefine
>dispose to call ClassName::free_object (note: use C version's name).
>
>---------------------------------------------------------------
> Paul Des Rivieres Senior Computer Analyst/Programmer
> Communications Security Establishment, Govt of Canada, Ottawa
> pdesrivi@cse.dnd.ca Voice: (613)991-8796 Fax: (613)991-8811
I use simmilar approach, when I want to access C++ library from
Smalltalk.
Vlastimil Adamovsky
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads