comp.lang.ada
 help / color / mirror / Atom feed
From: "Robert I. Eachus" <rieachus@comcast.net>
Subject: Re: Mixed languages and frustration.
Date: Tue, 14 Oct 2003 20:48:41 GMT
Date: 2003-10-14T20:48:41+00:00	[thread overview]
Message-ID: <3F8C6124.5040208@comcast.net> (raw)
In-Reply-To: pan.2003.10.14.20.30.30.107171.1209@nospam.net

Freejack wrote:
> Alright, so I'm sitting here trying to juggle between C pointers and Ada
> access types/allocators, with moderate success. And I start wondering to
> myself "How many people on comp.lang.ada nearly blow a fuse when doing
> the same thing?"
> 
> So I'm curious, are juggling the two types(pun intended) as chaffing for
> you as it is for me? Maybe I just dont know enough about the Interfaces
> libs yet.

No, eventually you will learn to do it the way we do.  Create a package 
that contains all the C cruft and hides it from anyone using the 
package.  The basic rule is that if you are using C pointers, the 
visible Ada abstraction should be a private--or limited private type. 
That way all the headaches are confined to one section of code.

Oh, and don't forget that you can have several Ada subprograms (usually 
with the same name) that correspond to a single C function.  Also often 
you want to have the Ada "wrapper" subprogram translate -1, etc. return 
values as exceptions.  This is expecially true with those C functions 
that either use the storage your pass them, or allocate storage if the 
pointer passed is null.  Treating that on the Ada side as a procedure 
and a function that happen to have the same name is often the right 
binding.  (And even then, the wrapper function may copy the return value 
when the C function does the allocation into an Ada structure, free the 
pointer than return the structure.  Sounds a lot more complex than it is.)

-- 
                                                     Robert I. Eachus

"Quality is the Buddha. Quality is scientific reality. Quality is the 
goal of Art. It remains to work these concepts into a practical, 
down-to-earth context, and for this there is nothing more practical or 
down-to-earth than what I have been talking about all along...the repair 
of an old motorcycle."  -- from Zen and the Art of Motorcycle 
Maintenance by Robert Pirsig




  reply	other threads:[~2003-10-14 20:48 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-10-14 20:24 Mixed languages and frustration Freejack
2003-10-14 20:48 ` Robert I. Eachus [this message]
2003-10-14 20:53 ` sk
2003-10-14 21:53 ` Wes Groleau
2003-10-15  0:01   ` Freejack
2003-10-15  2:58   ` Jeffrey Carter
2003-10-15  4:32     ` Wes Groleau
2003-10-15  4:24 ` Steve
2003-10-15 15:50 ` Stephen Leake
2003-10-16  6:40   ` Ole-Hjalmar Kristensen
replies disabled

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