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=-0.9 required=5.0 tests=BAYES_00,FORGED_GMAIL_RCVD, FREEMAIL_FROM autolearn=no autolearn_force=no version=3.4.4 X-Google-Thread: 103376,74bc23dcb20218db,start X-Google-NewGroupId: yes X-Google-Attributes: gida07f3367d7,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!postnews.google.com!k33g2000yqc.googlegroups.com!not-for-mail From: resander Newsgroups: comp.lang.ada Subject: How to access this package written in C? Date: Wed, 21 Apr 2010 09:43:02 -0700 (PDT) Organization: http://groups.google.com Message-ID: <4e9d2aaf-c0a6-4798-b838-8f5b7c4a39d1@k33g2000yqc.googlegroups.com> NNTP-Posting-Host: 82.5.106.54 Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 X-Trace: posting.google.com 1271868182 17739 127.0.0.1 (21 Apr 2010 16:43:02 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Wed, 21 Apr 2010 16:43:02 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: k33g2000yqc.googlegroups.com; posting-host=82.5.106.54; posting-account=5kIDUAkAAACEMLy16tM5OtzZtznE-9-5 User-Agent: G2/1.0 X-HTTP-UserAgent: Mozilla/5.0 (X11; U; Linux i686; en-GB; rv:1.9.0.19) Gecko/2010040118 Ubuntu/8.10 (intrepid) Firefox/3.0.19,gzip(gfe) Xref: g2news1.google.com comp.lang.ada:10116 Date: 2010-04-21T09:43:02-07:00 List-Id: I am working on software that manipulates SQL databases via a GUI. It is written in C or C++ without classes and compiled on Linux. Would also want it to run on Windows eventually. This software has essentially one entry procedure: int guidb ( int appno , int recaddress ); // in C which returns an outcome as an int, takes an int appno which specifies application and an address of a record in recaddress. The latter is used for passing the memory address of any recordtype variable and is cast to a byte address inside guidb. guidb uses appno to locate field-offsets and length of the recordtype in tables built by initialisation functions for all recordtypes that take part. Typical use in C/C++: typedef struct { int prodcode; float price; char descr [50]... } PRODUCT; typedef struct { bool bitesyou; int speciescode; char name[20] ... } ANIMAL ; void getproduct ( PRODUCT * pout , int * resultout ) { *resultout = guidb ( 0 , (int)pout ) ; } void addtozoo ( ANIMAL * a , int * resultout ) { *resultout = guidb ( 1 , (int)a ) ; } PRODUCT prod ; ANIMAL addthis ; int outcome ; // use as... getproduct ( &prod , &outcome ); // get addthis animal data then addtozoo ( &addthis , &outcome ); All wrappers like getproduct and addtozoo are automatically generated from other specs. That is easy in C by using fldoffset macro to get field offsets and sizeof(rectypename) to get record length and a cast that changes the interpretation of address to an int. Desired use in Ada (same as above): type PRODUCT is RECORD int prodcode; float price; char descr [50]...END RECORD; procedure getproduct ( p : out PRODUCT ; result : out int ) is begin result = guidb ( 0 , address_of(p) how ??? ) ; end prod : PRODUCT; outcome : int ; getproduct ( prod , outcome ); To be able to use the guidb with Ada I need to know how to: - get the memory address carried (how?) by the record formal parameter - obtain field offsets for a record type - obtain length of a record object/variable How to do this in in Ada? If it cannot be done, can the interface above be changed to make it possible? Ken