From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: 103376,bae62a394f8c9d83 X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news3.google.com!news4.google.com!news2.volia.net!newsfeed01.sul.t-online.de!t-online.de!newsfeed.inode.at!news.hispeed.ch!linux2.krischik.com!news From: Martin Krischik Newsgroups: comp.lang.ada Subject: Re: ada binding Date: Thu, 09 Feb 2006 20:34:59 +0100 Organization: Cablecom Newsserver Message-ID: <3220036.snWfkaaEov@linux1.krischik.com> References: <1142859.ZZbdis6YEU@linux1.krischik.com> NNTP-Posting-Host: 84-74-134-212.dclient.hispeed.ch Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-15 Content-Transfer-Encoding: 8Bit X-Trace: news.hispeed.ch 1139513756 29443 84.74.134.212 (9 Feb 2006 19:35:56 GMT) X-Complaints-To: news@hispeed.ch NNTP-Posting-Date: Thu, 9 Feb 2006 19:35:56 +0000 (UTC) User-Agent: KNode/0.10.1 Xref: g2news1.google.com comp.lang.ada:2827 Date: 2006-02-09T20:34:59+01:00 List-Id: Szymon Guz wrote: > Martin Krischik napisa?(a): >> Szymon Guz wrote: >> >>> Maciej Sobczak napisa?(a): >>>> Szymon Guz wrote: >>>> >>>>> how to make an Ada binding for a "C++" class using this C layer ? >>>> Basically, if the C++ class is not a template, but just plain "classic" >>>> OO stuff, then you can write a wrapper around it in C, which will still >>>> be OO, but without the syntax sugar of real class. Something along >>>> this: >>>> >>>> // an existing C++ class: >>>> class MyClass >>>> { >>>> public: >>>> void myFun(); >>>> }; >>>> >>>> // a C wrapper: >>>> extern "C" >>>> void * MyClass_new() >>>> { >>>> return new MyClass; >>>> } >>>> >>>> extern "C" >>>> void MyClass_delete(void *p) >>>> { >>>> delete static_cast(p); >>>> } >>>> >>>> extern "C" >>>> void MyClass_myFun(void *vp) >>>> { >>>> MyClass *mcp = static_cast(vp); >>>> mcp->myFun(); >>>> } >>>> >>>> // and so on. >>>> >>>> Depending on the level of isolation that you want to achieve and the >>>> level of type safety that you want to retain, hiding the object behind >>>> void* might or might not be the best choice, but this is to give you >>>> the idea. Above, MyClass_new, MyClass_delete and MyClass_myFun are >>>> plain C functions (you can extract their declarations to separate >>>> header file) and you can interface them from just about any sensible >>>> language in existence and from Ada in particular. >>>> >>>> >>> OK, but what about using the class fields : >>> >>> class MyClass >>> { >>> public: >>> int X; >>> int *p_X; >>> } >>> >>> and what about inheriting this from the class in Ada, is it possible ? >> >> If you are planning to inheriting then you need to directly bind to the >> C++ class. Only one compiler offers that (GNAT). Start reading here: >> >> http://gcc.gnu.org/onlinedocs/gcc-4.0.2/gnat_rm/Pragma-CPP_005fClass.html >> >> Martin > > I know but I wander if I can do that using other compilers and with the > middle layer written in C. You would need to use proxy classes then. Just as much work :-( Martin -- mailto://krischik@users.sourceforge.net Ada programming at: http://ada.krischik.com