From: "Jeffrey R. Carter" <spam.not.jrcarter@acm.not.spam.org>
Subject: Re: generic package with procedure paramter gives "not subtype conformant with declaration"
Date: Mon, 02 Oct 2006 03:24:30 GMT
Date: 2006-10-02T03:24:30+00:00 [thread overview]
Message-ID: <OD%Tg.220137$1i1.136242@attbi_s72> (raw)
In-Reply-To: <1159738009.962575.108920@i42g2000cwa.googlegroups.com>
cl1 wrote:
>
> This is a very good concept. Is there a mechanism in ada to allow:
>
> My_Void_Ptr := My_C_Float'Access;
>
> where My_C_Float could be My_New_Type or My_Integer, etc.
> I ask, because my code does this and i was using the System.Address as
> a catch all. Once i store the access in the pointer i no longer need to
> know
> what type it is. I just need the reference to pass to the C code. For
> instance:
If the access values come from Ada, it gets a bit more complicated.
However, C pointers are convertible from one type to another, IIRC, so
that works for you. You need to declare a convention-C access type for
the type you use, store the 'access in one of those, then unchecked
convert that value to the void pointer type. A generic can make that easier:
with Ada.Unchecked_Conversion;
...
type Void_Ptr is ...
...
generic -- Void_Conversion
type T (<>) is limited private;
package Void_Conversion is
type T_Ptr is access all T;
pragma Convention (C, T_Ptr);
function To_Void_Ptr is new Ada.Unchecked_Conversion
(Source => T_Ptr, Target => Void_Ptr);
end Void_Conversion;
Then you can do
package C_Float_Convert is new Void_Conversions (T => C_Float);
T_Ptr : constant C_Float_Convert.T_Ptr := My_C_Float'access;
My_Void_Ptr : Void_Ptr := C_Float_Convert.To_Void_Ptr (T_Ptr);
> Now that i know that is the rule. I not only understand what was
> causing
> the problem, but why.
That's usually a good thing.
--
Jeff Carter
"Monsieur Arthur King, who has the brain of a duck, you know."
Monty Python & the Holy Grail
09
next prev parent reply other threads:[~2006-10-02 3:24 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2006-09-30 21:20 generic package with procedure paramter gives "not subtype conformant with declaration" cl1
2006-10-01 1:27 ` Jeffrey R. Carter
2006-10-01 6:02 ` cl1
2006-10-01 19:43 ` Jeffrey R. Carter
2006-10-01 21:26 ` cl1
2006-10-01 23:17 ` tmoran
2006-10-02 4:46 ` cl1
2006-10-02 3:24 ` Jeffrey R. Carter [this message]
2006-10-02 4:31 ` cl1
2006-10-02 7:17 ` Alex R. Mosteo
2006-10-02 20:04 ` Jeffrey R. Carter
2006-10-03 18:49 ` cl1
2006-10-01 7:18 ` Simon Wright
2006-10-01 19:42 ` cl1
2006-10-01 20:18 ` Robert A Duff
2006-10-01 21:32 ` cl1
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox