🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.lang.eiffel
Article #1112

Calling C++ from C/Eiffel

#1112
From: Paul Des Rivieres
Date: Wed, 20 Dec 1995 18:22
36 lines
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
Technical Details
Message-ID: <30D85476.2D63E6AE@cse.dnd.ca>
Path: arc1-ca.pugleaf.net!manitou.cse.dnd.ca!usenet

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!manitou.cse.dnd.ca!usenet
From: Paul Des Rivieres <pdesrivi@cse.dnd.ca>
Newsgroups: comp.lang.eiffel,comp.lang.c,comp.lang.c++
Subject: Calling C++ from C/Eiffel
Date: Wed, 20 Dec 1995 13:22:46 -0500
Organization: CSE
Message-ID: <30D85476.2D63E6AE@cse.dnd.ca>
NNTP-Posting-Host: quasis.cse.dnd.ca
Mime-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
X-Mailer: Mozilla 2.0b3 (X11; I; Linux 1.3.20 i486)
CC: support@eiffel.com