From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,FREEMAIL_FROM autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: 103376,23ca868289d9f0c X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news2.google.com!news3.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!newsfeed00.sul.t-online.de!t-online.de!newsfeed.freenet.de!newsfeed0.kamp.net!newsfeed.kamp.net!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail From: "Alex R. Mosteo" Newsgroups: comp.lang.ada Subject: Re: generic package with procedure paramter gives "not subtype conformant with declaration" Date: Mon, 02 Oct 2006 09:17:26 +0200 Message-ID: <4obsnvFdgavuU1@individual.net> References: <1159651201.121690.130430@b28g2000cwb.googlegroups.com> <1159682538.644835.248030@m7g2000cwm.googlegroups.com> <3UUTg.1003037$084.701942@attbi_s22> <1159738009.962575.108920@i42g2000cwa.googlegroups.com> <1159763506.841048.175930@m73g2000cwd.googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7Bit X-Trace: individual.net c1U3NkRFdtykTK2DGL531QWkOg8IoAJLIXluB65XuoUaWnN14= User-Agent: KNode/0.10.4 Xref: g2news2.google.com comp.lang.ada:6836 Date: 2006-10-02T09:17:26+02:00 List-Id: 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