* Re: Mixed languages and frustration.
2003-10-14 20:24 Mixed languages and frustration Freejack
@ 2003-10-14 20:48 ` Robert I. Eachus
2003-10-14 20:53 ` sk
` (3 subsequent siblings)
4 siblings, 0 replies; 10+ messages in thread
From: Robert I. Eachus @ 2003-10-14 20:48 UTC (permalink / raw)
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
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: Mixed languages and frustration.
2003-10-14 20:24 Mixed languages and frustration Freejack
2003-10-14 20:48 ` Robert I. Eachus
@ 2003-10-14 20:53 ` sk
2003-10-14 21:53 ` Wes Groleau
` (2 subsequent siblings)
4 siblings, 0 replies; 10+ messages in thread
From: sk @ 2003-10-14 20:53 UTC (permalink / raw)
To: comp.lang.ada
Freejack <user@nospam.net>:
> Alright, so I'm sitting here trying to juggle between C '
> pointers and Ada access types/allocators, with moderate
> success ...
What exactly do you mean by "juggling" between C-pointers and
Ada access types ?
Are you :
1) Using Ada and trying to apply your C pointer knowledge ?
2) Using Ada bindings to "C" interfaces ?
Once you describe what you are trying to do, you might get
some useful responses from cla.
--
-------------------------------------------------
-- Merge vertically for real address
--
-- s n p @ t . o
-- k i e k c c m
-------------------------------------------------
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: Mixed languages and frustration.
2003-10-14 20:24 Mixed languages and frustration Freejack
2003-10-14 20:48 ` Robert I. Eachus
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:24 ` Steve
2003-10-15 15:50 ` Stephen Leake
4 siblings, 2 replies; 10+ messages in thread
From: Wes Groleau @ 2003-10-14 21:53 UTC (permalink / raw)
If you _really_ want to to pass an Ada access value
directly to a C pointer, without the precautions
and engineering suggested by others...
If XYZ is an Ada access type, then
the C pointer to the heap object is XYZ.all'Address
--
Wes Groleau
----
The man who reads nothing at all is better educated
than the man who reads nothing but newspapers.
-- Thomas Jefferson
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: Mixed languages and frustration.
2003-10-14 21:53 ` Wes Groleau
@ 2003-10-15 0:01 ` Freejack
2003-10-15 2:58 ` Jeffrey Carter
1 sibling, 0 replies; 10+ messages in thread
From: Freejack @ 2003-10-15 0:01 UTC (permalink / raw)
On Tue, 14 Oct 2003 17:53:13 -0400, Wes Groleau wrote:
> If you _really_ want to to pass an Ada access value directly to a C
> pointer, without the precautions and engineering suggested by others...
>
> If XYZ is an Ada access type, then
>
> the C pointer to the heap object is XYZ.all'Address
I dont mind the precautions. I was just ranting. I'm actually making
pretty good headway. I just sometimes get tripped up from time to time.
Freejack
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: Mixed languages and frustration.
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
1 sibling, 1 reply; 10+ messages in thread
From: Jeffrey Carter @ 2003-10-15 2:58 UTC (permalink / raw)
Wes Groleau wrote:
>
> If XYZ is an Ada access type, then
>
> the C pointer to the heap object is XYZ.all'Address
This will usually work, but is not guaranteed to. System.Address is a
private type because there are systems where an address doesn't map
neatly to an integer, as a C pointer must.
--
Jeff Carter
"Death awaits you all, with nasty, big, pointy teeth!"
Monty Python & the Holy Grail
20
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: Mixed languages and frustration.
2003-10-15 2:58 ` Jeffrey Carter
@ 2003-10-15 4:32 ` Wes Groleau
0 siblings, 0 replies; 10+ messages in thread
From: Wes Groleau @ 2003-10-15 4:32 UTC (permalink / raw)
Jeffrey Carter wrote:
> Wes Groleau wrote:
>> If XYZ is an Ada access type, then
>>
>> the C pointer to the heap object is XYZ.all'Address
>
> This will usually work, but is not guaranteed to. System.Address is a
> private type because there are systems where an address doesn't map
> neatly to an integer, as a C pointer must.
However, contrary to a popular belief among
Ada programmers, unchecked conversion from
access to address will usually NOT work on
most systems.
--
Wes Groleau
"Grant me the serenity to accept those I cannot change;
the courage to change the one I can;
and the wisdom to know it's me."
-- unknown
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: Mixed languages and frustration.
2003-10-14 20:24 Mixed languages and frustration Freejack
` (2 preceding siblings ...)
2003-10-14 21:53 ` Wes Groleau
@ 2003-10-15 4:24 ` Steve
2003-10-15 15:50 ` Stephen Leake
4 siblings, 0 replies; 10+ messages in thread
From: Steve @ 2003-10-15 4:24 UTC (permalink / raw)
"Freejack" <user@nospam.net> wrote in message
news:pan.2003.10.14.20.30.30.107171.1209@nospam.net...
> 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.
I too find it frustrating at times dealing with interfaces. This is not
unique to interfacing between Ada and C. I have the same frustrations
interfacing with Delphi.
My greatest frustration usually comes from poorly documented interfaces
where some behaviour is presumed. Sometimes it gets really ugly when
tasking (or multiple threads) is involved.
Steve
(The Duck)
> Also, I'm gonna post up my project to a hosting site once it looks
> remotely sane. Then you'll see just how crummy a developer I really
> am.(Something which is becoming abundantly clear to me as I progress.)
>
> Hope nobody barfs. Heh.
>
> Freejack
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: Mixed languages and frustration.
2003-10-14 20:24 Mixed languages and frustration Freejack
` (3 preceding siblings ...)
2003-10-15 4:24 ` Steve
@ 2003-10-15 15:50 ` Stephen Leake
2003-10-16 6:40 ` Ole-Hjalmar Kristensen
4 siblings, 1 reply; 10+ messages in thread
From: Stephen Leake @ 2003-10-15 15:50 UTC (permalink / raw)
Freejack <user@nospam.net> writes:
> 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?"
I try to avoid code in C at all costs.
When I do need to pass pointers to C, I just use 'Address on the Ada
side. It's not guarantteed portable, but neither is the C code, so
it's good enough. And it's far easier to get right, and usually more
efficient, than messing with Interfaces.C pointer stuff.
--
-- Stephe
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: Mixed languages and frustration.
2003-10-15 15:50 ` Stephen Leake
@ 2003-10-16 6:40 ` Ole-Hjalmar Kristensen
0 siblings, 0 replies; 10+ messages in thread
From: Ole-Hjalmar Kristensen @ 2003-10-16 6:40 UTC (permalink / raw)
>>>>> "SL" == Stephen Leake <Stephe.Leake@nasa.gov> writes:
SL> Freejack <user@nospam.net> writes:
>> 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?"
SL> I try to avoid code in C at all costs.
SL> When I do need to pass pointers to C, I just use 'Address on the Ada
SL> side. It's not guarantteed portable, but neither is the C code, so
SL> it's good enough. And it's far easier to get right, and usually more
SL> efficient, than messing with Interfaces.C pointer stuff.
SL> --
SL> -- Stephe
Yes. And in the same spirit, to go in the opposite direction, if you
have got a C pointer, just declare an Ada object and use an address
rep clause to put it where the pointer points. Same caveats apply.
--
If you are going to shoot, shoot, don't talk.
Il Brutto
^ permalink raw reply [flat|nested] 10+ messages in thread