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-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,31c63f07e48d5471 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2003-02-18 11:50:05 PST Path: archiver1.google.com!postnews1.google.com!not-for-mail From: rod.chapman@praxis-cs.co.uk (Rod Chapman) Newsgroups: comp.lang.ada Subject: Re: Ada to 'C' parameter passing problem Date: 18 Feb 2003 11:50:04 -0800 Organization: http://groups.google.com/ Message-ID: References: NNTP-Posting-Host: 213.152.53.239 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit X-Trace: posting.google.com 1045597805 20304 127.0.0.1 (18 Feb 2003 19:50:05 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: 18 Feb 2003 19:50:05 GMT Xref: archiver1.google.com comp.lang.ada:34212 Date: 2003-02-18T19:50:05+00:00 List-Id: Pat.Donahue@msfc.nasa.gov (Patrick) wrote in message news:... > I am using GNAT Ada on Linux. I am trying to port from a Sun > (Solaris) implementation. I didn't write the Ada or 'C' myself, but > am trying to make it work on Linux. This code looks mildly horrible. All that messing about with 'Address and Unchecked_Conversion is in very poor style. My advice: 1) Work out what the true Ada mode of each parameter should be. Just because C forces pass-pointer-by-copy mechanism doesn't mean that you should try to emulate that directly in Ada. Is each pointed-to parameter intended to be read, updated or both? That tells you that each parameter should be "in" , "out", or "in out" in Ada terms. 2) What type is each by-reference parameter actually pointing at? (Integer or "zero-terminated bounded array of character" are probable answers) - that tells you the Ada types that you should be passing. 3) Check out Annex B.3 - The package Interfaces.C gives you lots of stuff (e.g. for turning an Ada String into a null-terminated C string) that's useful. Also read up the small print on what Pragma Import does when you use Convention "C" - that defines how Ada parameters are passed to C - very useful. 4) A C function that has multiple side-effects via by-reference parameters shouldn't be a function in Ada at all - it's a procedure! That should allow you to write a clean Ada binding. - Rod Chapman, SPARK Team, Praxis Critical Systems