comp.lang.ada
 help / color / mirror / Atom feed
From: "Randy Brukardt" <randy@rrsoftware.com>
Subject: Re: String filtering
Date: Wed, 5 Oct 2005 18:04:21 -0500
Date: 2005-10-05T18:04:21-05:00	[thread overview]
Message-ID: <2MydnS2z3bCJxtneRVn-qA@megapath.net> (raw)
In-Reply-To: wccu0fya3c3.fsf@shell01.TheWorld.com

"Robert A Duff" <bobduff@shell01.TheWorld.com> wrote in message
news:wccu0fya3c3.fsf@shell01.TheWorld.com...
...
> And there's some run-time overhead for access parameters -- they carry
> run-time accessibility-level info with them.

That's not just an overhead issue, but also potentially a safety issue, as
the accessibility checks are done at run-time. Sometimes you need that, but
the result is that the location of the call determines whether or not
Program_Error is raised -- which means that only testing (rather than the
Ada compiler) will ferret out problems. Wheras the same code with an in out
parameter would be illegal (and have no run-time overhead). Much better from
a safety perspective.

To give an example (using procedures so it's legal Ada code):

     type T is tagged ...;
     type AT is access all T;

     procedure P1 (O : in out T) is
        P : AT := O'access; -- Illegal, accessibility fails.
     begin
        ....
     end P1;

     procedure P2 (O : access T) is
       P : AT := O; -- Might raise Program_Error, depending on the point of
the call.
     begin
       ...
     end P2;

     Obj : T;
     Obj2 : aliased T; -- Extra aliased needed here, even though it has no
effect.

     P1 (Obj);
     P2 (Obj2'Access); -- Extra 'Access here, even though the code is
essentially the same.

Using access parameters clutters both the objects and the call site, adds
run-time overhead, and in Ada 200Y, even might add null checks (unless you
hadd even more clutter with "not null" in the parameter declaration).

And what's the difference? For a tagged type, the code generated (and the
evaluation order issues) for "in out" and "access" are essentially
identical, but one is allowed and the other isn't. Makes lots of sense.

> Furthermore, there's (annoyingly) no way to declare a formal parameter
> aliased.  So you use 'access' where 'in out' should suffice, or you
> declared tagged types that have no need for a tag.

There are no such types. :-) [OK, I'm kidding, but there certainly aren't
many such types.]

> Yes, there are workarounds for the lack of [in] out params on functions
> -- but they have global consequences on your code.

Yes,  indeed.

                        Randy.







  reply	other threads:[~2005-10-05 23:04 UTC|newest]

Thread overview: 71+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-09-27  6:27 String filtering David Trudgett
2005-09-27  7:38 ` Jacob Sparre Andersen
2005-09-27  9:13   ` David Trudgett
2005-09-27  9:49     ` Dmitry A. Kazakov
2005-09-27 11:01       ` Martin Dowie
2005-09-27 11:12         ` Martin Dowie
2005-09-27 12:54           ` Dmitry A. Kazakov
2005-09-27 13:42             ` Martin Dowie
2005-09-27 14:24               ` Dmitry A. Kazakov
2005-09-28  0:06                 ` David Trudgett
2005-09-28  8:15                   ` Dmitry A. Kazakov
2005-09-28 10:39                     ` David Trudgett
2005-09-28 20:55                       ` Simon Wright
2005-09-28 21:53                         ` Martin Dowie
2005-09-28  9:08                   ` Jacob Sparre Andersen
2005-09-28  9:54                     ` David Trudgett
2005-09-29 14:05                       ` Georg Bauhaus
2005-10-01 19:02                         ` tmoran
2005-10-02  6:38                           ` David Trudgett
2005-10-02 14:11                             ` Martin Dowie
2005-10-02 22:40                               ` David Trudgett
2005-10-03  5:56                                 ` Martin Dowie
2005-10-03 10:33                           ` Georg Bauhaus
2005-09-28 18:21                   ` Jeffrey R. Carter
2005-09-28 21:00                   ` Simon Wright
2005-09-27 11:22         ` David Trudgett
2005-09-27 11:15       ` David Trudgett
2005-09-27 13:21         ` Dmitry A. Kazakov
2005-09-27 13:43           ` Martin Dowie
2005-09-28  0:51           ` David Trudgett
2005-09-28 12:02             ` Dmitry A. Kazakov
2005-09-28 13:25             ` Marc A. Criley
2005-09-29 22:42           ` Randy Brukardt
2005-09-30 17:54             ` Robert A Duff
2005-10-02  6:57               ` Steve Whalen
2005-10-02 14:14                 ` Martin Dowie
2005-10-03  1:21                 ` Robert A Duff
2005-10-03  7:44                   ` Jacob Sparre Andersen
2005-10-03  8:56                     ` Dmitry A. Kazakov
2005-10-03  9:25                       ` Jean-Pierre Rosen
2005-10-03 20:17                         ` Ada Notation Jeffrey R. Carter
2005-10-03 20:41                           ` Georg Bauhaus
2005-10-05 17:16                             ` Andre
2005-10-05 18:23                               ` Ludovic Brenta
2005-10-05 18:24                               ` Jeffrey R. Carter
2005-10-04 15:13                           ` brian.b.mcguinness
2005-10-04 17:00                     ` String filtering Robert A Duff
2005-10-05  8:19                       ` Jean-Pierre Rosen
2005-10-05 11:25                         ` Robert A Duff
2005-10-04 19:47                     ` Björn Persson
2005-10-05 14:14                       ` Dmitry A. Kazakov
2005-10-03 10:06                   ` Steve Whalen
2005-10-03 17:43                   ` tmoran
2005-10-03 17:59                     ` Robert A Duff
2005-10-05 23:04                       ` Randy Brukardt [this message]
2005-09-27 13:52         ` Jacob Sparre Andersen
2005-09-28  1:01           ` David Trudgett
2005-09-28  1:50             ` David Trudgett
2005-09-27 14:08         ` Georg Bauhaus
2005-09-27 14:09         ` Marc A. Criley
2005-09-28  1:09           ` David Trudgett
2005-09-28 21:09           ` Simon Wright
2005-09-27 17:59         ` tmoran
2005-09-28  1:20           ` David Trudgett
2005-09-27 17:47     ` Jeffrey R. Carter
2005-09-28  1:29       ` David Trudgett
2005-09-28 18:32         ` Jeffrey R. Carter
2005-09-27  7:41 ` tmoran
2005-09-27  9:17   ` David Trudgett
2005-09-28  1:54 ` Steve
2005-09-28  2:20   ` David Trudgett
replies disabled

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