From: "cl1" <charles.w.lambert@gmail.com>
Subject: Re: generic package with procedure paramter gives "not subtype conformant with declaration"
Date: 1 Oct 2006 14:26:50 -0700
Date: 2006-10-01T14:26:50-07:00 [thread overview]
Message-ID: <1159738009.962575.108920@i42g2000cwa.googlegroups.com> (raw)
In-Reply-To: <3UUTg.1003037$084.701942@attbi_s22>
Jeffrey R. Carter wrote:
> cl1 wrote:
> > <snip>
>
> 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
next prev parent reply other threads:[~2006-10-01 21:26 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 [this message]
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
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