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 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!news4.google.com!news3.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!wns14feed!worldnet.att.net!attbi_s72.POSTED!53ab2750!not-for-mail From: "Jeffrey R. Carter" Organization: jrcarter at acm dot org User-Agent: Thunderbird 1.5.0.7 (Windows/20060909) MIME-Version: 1.0 Newsgroups: comp.lang.ada Subject: Re: generic package with procedure paramter gives "not subtype conformant with declaration" 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> In-Reply-To: <1159738009.962575.108920@i42g2000cwa.googlegroups.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Message-ID: NNTP-Posting-Host: 12.201.97.213 X-Complaints-To: abuse@mchsi.com X-Trace: attbi_s72 1159759470 12.201.97.213 (Mon, 02 Oct 2006 03:24:30 GMT) NNTP-Posting-Date: Mon, 02 Oct 2006 03:24:30 GMT Date: Mon, 02 Oct 2006 03:24:30 GMT Xref: g2news2.google.com comp.lang.ada:6833 Date: 2006-10-02T03:24:30+00:00 List-Id: 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