comp.lang.ada
 help / color / mirror / Atom feed
From: "Jeffrey R. Carter" <spam.not.jrcarter@acm.not.spam.org>
Subject: Re: generic package with procedure paramter gives "not subtype conformant with declaration"
Date: Sun, 01 Oct 2006 19:43:59 GMT
Date: 2006-10-01T19:43:59+00:00	[thread overview]
Message-ID: <3UUTg.1003037$084.701942@attbi_s22> (raw)
In-Reply-To: <1159682538.644835.248030@m7g2000cwm.googlegroups.com>

cl1 wrote:
> 
> I understand the reason for using access types with convention C, but
> that
> will not work for this situation. Everywhere i have used System.Address
> the code
> does not know, does not care what type or subprogram signature is
> stored there, and will
> not use it other than to pass it along to some c function that knows
> what to do with it. If
> there is a System.Address being used that doesn't fit that, then it is
> a bug. I also choose
> not to use 'type void_ptr is new System.Address;' specifically becuase
> that is what
> System.Address is. Also someone once told me that writing code that
> requires the user
> to with System; alerts the user that the code is system dependant. I
> like that idea. This
> code is system dependant. By that, I mean it is dependant on the
> processor and in
> some situations the operating system, not the compiler implementation.
> Well to be
> honest the Ada code isn't but the C code it interfaces with is
> (ffcall's avcall).

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.

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);

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.

-- 
Jeff Carter
"Monsieur Arthur King, who has the brain of a duck, you know."
Monty Python & the Holy Grail
09



  reply	other threads:[~2006-10-01 19:43 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 [this message]
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
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