comp.lang.ada
 help / color / mirror / Atom feed
From: Adam Beneschan <adambeneschan@gmail.com>
Subject: Re: Pointer to instance of indefinite array?
Date: Wed, 13 Aug 2014 08:32:18 -0700 (PDT)
Date: 2014-08-13T08:32:18-07:00	[thread overview]
Message-ID: <cc863592-3556-45ce-a1fd-ade463a81c42@googlegroups.com> (raw)
In-Reply-To: <lsf56u$fm5$1@dont-email.me>

On Wednesday, August 13, 2014 12:47:40 AM UTC-7, Georg Bauhaus wrote:

> Since 'Unrestricted_Access is not Ada but a GNAT specific pragma, 
> and since it is not strictly needed, I think that standard Ada's own 
> 'Unchecked_Acceess should be enough? 

No, because of a somewhat obscure rule that deals with 'Access on an array when the target type is access-to-unconstrained-array.  The rule is in 3.10.2(27-27.2).  The reason for the rule is that access-to-unconstrained-array types need to either carry or point to information about the bounds; and in implementations where the bounds have to be stored together with the data, and the access object points to the bounds, you don't want to force the program to store the bounds for *every* array.

Because of this, even if 'Unrestricted_Access compiles on GNAT in Per's example code, it would have to be tested to make sure it works.  If there's no bound information, then the resulting code will be incorrect.  I think GNAT stores the bounds next to the data, but I'm not sure. 

> I remember something about the ICC compiler supporting an implementation
> specific attribute similar to 'Unrestricted_Access. Is there a significant
> advantage in using 'Unrestricted_Access in user programs, perhaps suppression
> of more checks so that to something runs a lot faster?

'Unrestricted_Access in ICC Ada just allows you to get the 'Access of something that wouldn't otherwise be legal.  I think it's the same in GNAT, but I'm not positive.  Note that 'Unchecked_Access suppresses accessibility checks (allowing an access object to point to something on the stack that could disappear before the access object does), and therefore it allows you to violate the static accessibility rules, but it doesn't allow you to violate other rules.  For example, if you use X'Unchecked_Access, X still has to be aliased, and there are other rules that are still checked.  'Unrestricted_Access suppresses checks like that too.  (In addition (as Egil posted), it can be used on subprograms, for which Ada doesn't allow 'Unchecked_Access.)

So, no, 'Unrestricted_Access doesn't affect performance.  In any case, the only checks performed at run-time are accessibility-level checks, and 'Unchecked_Access suppresses those, so it's hard to come up with any further performance improvements.

                                 -- Adam

  parent reply	other threads:[~2014-08-13 15:32 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-08-13  2:07 Pointer to instance of indefinite array? NiGHTS
2014-08-13  2:09 ` Jeffrey Carter
2014-08-13  2:29 ` Shark8
2014-08-13  3:06   ` NiGHTS
2014-08-13  4:28     ` Jeffrey Carter
2014-08-13 16:06       ` NiGHTS
2014-08-13 17:43         ` Jeffrey Carter
2014-08-13 17:58         ` Shark8
2014-08-13 18:36         ` Dmitry A. Kazakov
2014-08-13  4:31     ` Per Sandberg
2014-08-13  7:47       ` Georg Bauhaus
2014-08-13  8:05         ` Egil H H
2014-08-13 15:32         ` Adam Beneschan [this message]
2014-08-14  8:03           ` Georg Bauhaus
2014-08-13 18:17       ` Niklas Holsti
replies disabled

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