comp.lang.ada
 help / color / mirror / Atom feed
* parameters in bindings
@ 1996-03-22  0:00 Mitch Gart
  1996-03-22  0:00 ` Robert Dewar
  1996-03-23  0:00 ` Adam Beneschan
  0 siblings, 2 replies; 5+ messages in thread
From: Mitch Gart @ 1996-03-22  0:00 UTC (permalink / raw)


Suppose we have a C function

    int f (int * param1, int ** param2);

(For the non-C crowd this is a function named f which takes 2 
parameters and returns an integer.  The first parameter is a 
pointer to an integer and the second is a pointer to a pointer 
to an integer.)

How do we best interface to this in Ada 95?

Method 1 uses "in out" parameters and would be the best Ada
interface (ignoring the question about "in out" versus "out"):

    type int_access is access all int;		-- int defined somewhere

    function f (param1: in out int;
		param2: in out int_access) return int;

This is unfortunately illegal, out parameters are not allowed for 
functions.  There have been long threads discussing this restriction
and it sounds like it will not be changed.

Method 2 uses anonymous access types.  I have used this method all
over the place in a number of bindings such as X11Ada and Win32Ada.

    type int_access is access all int;		-- int defined somewhere

    function f (param1: access int;
		param2: access int_access) return int;

I have recently learned this is a fundamental error because an Ada 95 
rule makes passing null for param1 or param2 illegal (see LRM 4.2(7)
and 4.6(49)).  Many of the C functions in the bindings allow null
to be passed, with a meaning like  "if the parameter is non-null assign
a result to the place where it points".

Method 3 uses all named access types:

    type int_access is access all int;		-- int defined somewhere
    type int_access_access is access all int_access;

    function f (param1: int_access;
		param2: int_access_access) return int;

This works but to me it seems ugly because extra access types are 
introduced which are otherwise unnecessary.

Because of the illegal-null problem in method 2 I guess I'm going to
make a wholesale change to the bindings and use method 3.  Before I
make that change does anybody have any better ideas?

- Mitch Gart
- mg@inmet.com




^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~1996-03-26  0:00 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1996-03-22  0:00 parameters in bindings Mitch Gart
1996-03-22  0:00 ` Robert Dewar
1996-03-26  0:00   ` Mitch Gart
1996-03-26  0:00     ` Robert Dewar
1996-03-23  0:00 ` Adam Beneschan

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