comp.lang.ada
 help / color / mirror / Atom feed
From: "Alex R. Mosteo" <devnull@mailinator.com>
Subject: Re: generic package with procedure paramter gives "not subtype conformant with declaration"
Date: Mon, 02 Oct 2006 09:17:26 +0200
Date: 2006-10-02T09:17:26+02:00	[thread overview]
Message-ID: <4obsnvFdgavuU1@individual.net> (raw)
In-Reply-To: 1159763506.841048.175930@m73g2000cwd.googlegroups.com

cl1 wrote:

> 
> Jeffrey R. Carter wrote:
>> 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;
> 
> Genius, pure genius! :D
> 
> Thank you.

You can see an example of a binding using this technique in 

http://sourceforge.net/projects/ada-player

Therein are types coming from the C and Ada side being used in calls to the
C side.

It is an Ada-C binding for the robotic controller Player:

http://playerstage.sf.net



  reply	other threads:[~2006-10-02  7:17 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
2006-10-02  4:31           ` cl1
2006-10-02  7:17             ` Alex R. Mosteo [this message]
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