comp.lang.ada
 help / color / mirror / Atom feed
From: rod.chapman@praxis-cs.co.uk (Rod Chapman)
Subject: Re: Ada to 'C' parameter passing problem
Date: 18 Feb 2003 11:50:04 -0800
Date: 2003-02-18T19:50:05+00:00	[thread overview]
Message-ID: <cf2c6063.0302181150.55991a7e@posting.google.com> (raw)
In-Reply-To: ea3b54bb.0302180739.3cb6c159@posting.google.com

Pat.Donahue@msfc.nasa.gov (Patrick) wrote in message news:<ea3b54bb.0302180739.3cb6c159@posting.google.com>...
> 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.
<snip>

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



  parent reply	other threads:[~2003-02-18 19:50 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-02-18 15:39 Ada to 'C' parameter passing problem Patrick
2003-02-18 16:47 ` Jeffrey Carter
2003-02-18 19:50 ` Rod Chapman [this message]
2003-02-20  2:36   ` Matthew Heaney
2003-02-20  9:18     ` Rod Chapman
2003-02-20  9:43       ` Dmitry A. Kazakov
2003-02-20 22:05       ` Simon Wright
2003-02-21  9:53         ` Stuart Palin
2003-02-21 17:39           ` Jeffrey Carter
2003-02-21 18:12           ` Warren W. Gay VE3WWG
2003-02-21 20:25           ` Randy Brukardt
2003-02-24 23:53       ` Matthew Heaney
2003-02-25 17:21         ` Rod Chapman
  -- strict thread matches above, loose matches on Subject: below --
2003-02-21 16:52 Lionel.DRAGHI
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox