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=-0.9 required=5.0 tests=BAYES_00,FORGED_GMAIL_RCVD, FREEMAIL_FROM autolearn=no 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!postnews.google.com!i42g2000cwa.googlegroups.com!not-for-mail From: "cl1" Newsgroups: comp.lang.ada Subject: Re: generic package with procedure paramter gives "not subtype conformant with declaration" Date: 1 Oct 2006 14:26:50 -0700 Organization: http://groups.google.com Message-ID: <1159738009.962575.108920@i42g2000cwa.googlegroups.com> References: <1159651201.121690.130430@b28g2000cwb.googlegroups.com> <1159682538.644835.248030@m7g2000cwm.googlegroups.com> <3UUTg.1003037$084.701942@attbi_s22> NNTP-Posting-Host: 66.160.210.89 Mime-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" X-Trace: posting.google.com 1159738013 3556 127.0.0.1 (1 Oct 2006 21:26:53 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Sun, 1 Oct 2006 21:26:53 +0000 (UTC) In-Reply-To: <3UUTg.1003037$084.701942@attbi_s22> User-Agent: G2/1.0 X-HTTP-UserAgent: Mozilla/5.0 (Macintosh; U; PPC Mac OS X; en) AppleWebKit/418.9 (KHTML, like Gecko) Safari/419.3,gzip(gfe),gzip(gfe) Complaints-To: groups-abuse@google.com Injection-Info: i42g2000cwa.googlegroups.com; posting-host=66.160.210.89; posting-account=MCxsfw0AAABxs2rB6FOIOk-6XLUrvbBM Xref: g2news2.google.com comp.lang.ada:6828 Date: 2006-10-01T14:26:50-07:00 List-Id: Jeffrey R. Carter wrote: > cl1 wrote: > > > > The problem is that System.Address is not guaranteed to be the same as a > C pointer, so using it to interface with C makes your code compiler > dependent. In all versions of GNAT that I've used and bothered to check, > System.Address has been the same as a C pointer, but that could change > at any time. I did not know this. I am forever learning, it seems. > > For types, any convention-C access type will work for a void pointer > when the values come from C and are never dereferenced by the Ada. I > generally use "access all Integer" for that case, though some people > prefer to have a void type to designate: > > type Void is null record; > type Void_Ptr is access all Void; > pragma Convention (C, Void_Ptr); 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: package avcall is type Argument is record Value_Address : System.Address; end record; end avcall; generic type Any_Type is private; package avcall.register_type package Any_Type_Conversion is new System.Address_To_Access_Conversions(Any_Type); type Argument_Instance is record Instance_Value : Any_Type_Conversion.Object_Pointer; end record; function Concat(AList : Var_Args; Arg : Any_Type) return Var_Args is Info : Argument_Instance; begin Info.Instance_Value := Arg; Info.Value_Address := Any_Type_Conversion.To_Address(Info.Instance_Value); return AList; end; end avcall.register_type; This is how i'm currently doing things. How would i change my Argument.Value_Address from System.Address type to something like the Void_Ptr type you proposed? So that i can change: Info.Value_Address := Any_Type_Conversion.To_Address(Info.Instance_Value); to work with the Void_Ptr type. > > Since values of Void_Ptr are never dereferenced, the designated type > doesn't matter. > > For subprograms, it's more complicated because you have to match the > subprogram parameter and return type profile. In your case, though > (IIRC), the subprograms all have the same profile (that of your generic > formal subprogram), so the use of a convention-C access type seems to be > possible. > > > i'm using GPS which has gcc version 3.4.6 on mac os x 10.4.8 > > GPS is an IDE, not a compiler, but gcc 3.4.6 is; it's an Ada-95 > compiler. The compiler version is of interest because Ada 95's > accessibility rules differ from Ada 0X's. > > > I agree with you. > > However, I am confused about this. The procedure could be declared > > anywhere. How > > does the compiler know what scope the procedure that is supplied to the > > generic package is in? I mean can it ever know? If not, that means > > there > > is no foreseeable fix to this issue from my point of view. > > The compiler can't know the scope of the actual procedure in general; > that's why you can never store the 'access of a generic formal > procedure. The language assumes the worst case for safety. to quote another post in this thread: -And you wanted to do Av_Param_Instance'Access inside the generic? -That won't work, because the compiler can't check the rules about -X'Access, because it doesn't know enough about the actual parameter -passed to Av_Param_Instance. The accessibility rules come to mind. -Also, the fact that you can't do X'Access if X is intrinsic Now that i know that is the rule. I not only understand what was causing the problem, but why. > > -- > Jeff Carter > "Monsieur Arthur King, who has the brain of a duck, you know." > Monty Python & the Holy Grail > 09