comp.lang.ada
 help / color / mirror / Atom feed
From: Jere <jhb.chat@gmail.com>
Subject: Re: Comparing Access Types
Date: Fri, 10 Nov 2017 07:06:38 -0800 (PST)
Date: 2017-11-10T07:06:38-08:00	[thread overview]
Message-ID: <0e68d62f-6e81-4f48-998f-cccdb4c650a1@googlegroups.com> (raw)
In-Reply-To: <ou13tc$2de$1@gioia.aioe.org>

On Thursday, November 9, 2017 at 3:33:51 AM UTC-5, Dmitry A. Kazakov wrote:
> On 09/11/2017 06:37, Jere wrote:
> > 
> > 1.  Address_To_Access_Conversions is out (cannot use an incomplete type)
> > 2.  I cannot simply do var.all'Address (Again, incomplete type)
> 
> Of course you can.

When I use GNAT GPL 2016 I get the following error:
10:33 prefix of "Address" attribute cannot be an incomplete type

It works fine for other types of generic formals, but for incomplete 
types, it fails with an error like this.

> 
> > Is there some way to do this within the Ada standard or am I hamstrung
> > due to the incomplete type specification?
> > 
> > Also, why weren't <, >, <=, >= provided for access types.  Even if the
> > representation of an Access type is implementation defined, surely
> > those operators could have been defined.
> 
> No, in general case it cannot, in the spirit of the semantics that A < B 
> if the physical machine address of A < B. Actually even equality cannot 
> be for segmented memory but it felt good enough.
> 

I may not understand, but I don't see this as any issue.  Even when physical
memory is split into pages, banks, segments, etc., it can be organized into
unique locations.  I'm not suggesting that access values need to map directly
to memory addresses but it seems odd that an access type, which holds some
unique information about an object, cannot be ordered in some fashion.

> > A toned down example:
> > 
> > generic
> >     type Item_Type(<>);
> >     type Item_Access is access Item_Type;
> > package My_Package is
> >  <SNIPPED>
> 
> You have two options:
> 
> 1. Compare addresses, e.g.
> 
> with System; use System;
> 
> function "<" (Left,Right : Some_Type) return Boolean is
> begin
>     return (  Right.Reference /= null
>            and then
>               (  Left.Reference = null
>               or else
>                  Left.Reference.all'Address < Right.Reference.all'Address
>            )  );
> end "<";
> 
> 2. A better way is to use the native object's order:
> 
> generic
>     type Item_Type(<>);
>     type Item_Access is access Item_Type;
>     with function "=" (Left, Right : Item_Type) return Boolean is <>;
>     with function "<" (Left, Right : Item_Type) return Boolean is <>;
> package My_Package is
> 
> function "<" (Left,Right : Some_Type) return Boolean is
> begin
>     return (  Right.Reference /= null
>            and then
>               (  Left.Reference = null
>               or else
>                  Left.Reference.all < Right.Reference.all
>            )  );
> end "<";
> 
> -- 
> Regards,
> Dmitry A. Kazakov
> http://www.dmitry-kazakov.de

Ok, that makes sense.  If I have to do it that way, then I'll have
to push it off to the client in some fashion.  Though again, GNAT
won't currently let me do the first option yet.

Thanks



  parent reply	other threads:[~2017-11-10 15:06 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-11-09  5:37 Comparing Access Types Jere
2017-11-09  8:29 ` Simon Wright
2017-11-09  8:33 ` Dmitry A. Kazakov
2017-11-09 22:38   ` Robert A Duff
2017-11-10  8:35     ` Dmitry A. Kazakov
2017-11-10 15:11       ` Jere
2017-11-10 16:05       ` Robert A Duff
2017-11-10 16:30         ` Robert A Duff
2017-11-16  1:17           ` Randy Brukardt
2017-11-18 22:01             ` Robert A Duff
2017-11-20 22:25               ` Randy Brukardt
2017-11-21  0:30                 ` Shark8
2017-11-21  8:57                   ` Dmitry A. Kazakov
2017-11-22  1:01                     ` Randy Brukardt
2017-11-10 15:20     ` Jere
2017-11-10 16:00       ` Robert A Duff
2017-11-10 16:22         ` Jere
2017-11-10 15:06   ` Jere [this message]
2017-11-16  1:21     ` Randy Brukardt
2017-11-16  1:13 ` Randy Brukardt
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox