comp.lang.ada
 help / color / mirror / Atom feed
From: Alan Brain <aebrain@dynamite.com.au>
Subject: Re: how to pass access string across pragma C interface?
Date: 1997/06/25
Date: 1997-06-25T00:00:00+00:00	[thread overview]
Message-ID: <33B1E458.49F0@dynamite.com.au> (raw)
In-Reply-To: dewar.867078965@merv


Robert Dewar wrote:

> It is reasonable to assume that pointers to constrained array types are
> easily mapped to C pointers, but it is asking for trouble to pass
> pointers to unconstrained types. That is because the bounds information
> must be somehow present, and C cannot know anything about it.
> 
> Thus code that passes such pointers to C, and even more code that receives
> such pointers FROM C, is liable to be highly implementation dependent.

Correct. What you must do is to have a look at the compiler
documentation. For BOTH C and Ada compilers. For the C Compiler, this
will often mean looking at the source code for it (bleah). All Ada
compilers in my experience state somewhere what the compiler's native
representation of each data structure looks like. It took me 3 days to
find it in the DDCI manuals once, but they have improved markedly since
then.
For example, one implementation may look like:
2 bytes giving a tag for this data structure (uunconstrained array,
short unconstrained array, huge unconstrained array etc)
2-bytes giving an entry into a hash table of memory locations for start
and length OR 2 bytes for length and 4 bytes for start address if it's a
small unconstrained array.
Another implementation may be completely different: just a 4-bytes
length, with the data starting immediately afterwards.

As for C, C++... they vary as well. If you're incredibly fortunate, then
the internal representations might be identical. But in this case, I'd
still write a wrapper, and put this with the other machine-dependent
stuff, as different versions of the compilers can change their
representations without notice.
   
-- 
aebrain@dynamite.com.au     <> <>    How doth the little Crocodile
| Alan & Carmel Brain|      xxxxx       Improve his shining tail?
| Canberra Australia |  xxxxxHxHxxxxxx _MMMMMMMMM_MMMMMMMMM
100026.2014 compuserve o OO*O^^^^O*OO o oo     oo oo     oo  
                    By pulling MAERKLIN Wagons, in 1/220 Scale
See http://www.z-world.com/graphics/z/master/8856.gif for picture






  reply	other threads:[~1997-06-25  0:00 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1997-06-19  0:00 how to pass access string across pragma C interface? burch
1997-06-20  0:00 ` Anonymous
1997-06-22  0:00 ` David C. Hoos, Sr.
1997-06-23  0:00   ` Robert Dewar
1997-06-25  0:00     ` Alan Brain [this message]
1997-06-24  0:00 ` Matthew Heaney
replies disabled

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