From: SIMON Claude <claude.simon@equipement.gouv.fr>
Subject: Re: Run-Time Type Assignment
Date: Thu, 29 Aug 2002 15:52:27 +0200
Date: 2002-08-29T13:49:23+00:00 [thread overview]
Message-ID: <3D6E271B.538FDF52@equipement.gouv.fr> (raw)
In-Reply-To: H1LxwL.45o@world.std.com
Does a "limited access procedure" could be THE solution ?
Claude Simon
Ben Brosgol wrote:
>
> Bob Duff wrote:
>
> > > > GNAT supports downward closures via the 'Unrestricted_Access
> attribute,
> > > > but that's not Ada (unfortunately).
> > >
> > > What about using just the plain old 'Access attribute to pass a pointer
> to
> > > the procedure as a parameter? That is supported by all Ada 95 compilers.
> >
> > No, 'Access doesn't work. Typically, the loop body (the procedure to be
> > passed as a parameter) is more nested than the iterator, which makes
> > 'Access illegal.
> ... snip ...
> > GNAT's 'Unrestricted_Access attribute works in this case, but it is
> > nonportable and dangerous. The question was whether Pascal supports
> > features not supported by Ada: in this case, it does; the feature is
> > portable and safe (compared to 'Unrestricted_Access).
>
> The reason it is safe to pass nested subprograms as parameters in Pascal is
> that Pascal does not allow subprograms to be used as values for variables or
> placed in data structures. GNAT's 'Unrestricted_Access is just as safe,
> provided that you abide by the Pascal restrictions. (I.e.,
> Unrestricted_Access still entails the other checks required by the language;
> e.g. static subtype conformance for corresponding formals, matching
> conventions.) For example:
>
> procedure Test_Unrestricted_Access is
> type Acc is access procedure;
> Ref : Acc;
> procedure P1(N : Integer) is begin null; end P1;
> procedure P2;
> pragma Convention(C, P2);
> procedure P2 is begin null; end P2;
> begin
> Ref := P1'Unrestricted_Access; -- error
> Ref := P2'Unrestricted_Access; -- error
> declare
> procedure Q is begin null; end Q;
> begin
> Ref := Q'Unrestricted_Access; -- OK
> Ref := Q'Access; --error
> end;
> end Test_Unrestricted_Access;
>
> The lines indicated by the "-- error" comments were diagnosed as
> compile-time errors by GNAT.
>
> As for portability, if you are using GNAT why would you ever want to move to
> some other compiler? :-)
>
> Ben Brosgol
> Ada Core Technologies
next prev parent reply other threads:[~2002-08-29 13:52 UTC|newest]
Thread overview: 33+ messages / expand[flat|nested] mbox.gz Atom feed top
2002-08-28 6:53 Run-Time Type Assignment Robert C. Leif
2002-08-28 11:04 ` Robert Dewar
2002-08-28 13:35 ` Robert A Duff
2002-08-28 14:56 ` Larry Kilgallen
2002-08-28 14:31 ` Robert A Duff
2002-08-28 14:59 ` Lutz Donnerhacke
2002-08-28 22:32 ` Robert A Duff
2002-08-29 22:55 ` Dmitry A.Kazakov
2002-08-28 18:03 ` Frank J. Lhota
2002-08-28 18:37 ` Pat Rogers
2002-08-28 22:47 ` Robert A Duff
2002-08-29 13:32 ` Ben Brosgol
2002-08-29 13:52 ` SIMON Claude [this message]
2002-08-29 14:30 ` Robert A Duff
2002-08-29 18:27 ` Randy Brukardt
2002-08-29 14:56 ` Robert A Duff
2002-08-30 3:04 ` Ben Brosgol
2002-08-30 22:54 ` Robert A Duff
2002-08-29 15:09 ` Larry Kilgallen
2002-08-29 14:29 ` Marin D. Condic
2002-08-28 13:41 ` Robert A Duff
2002-08-28 17:15 ` Hyman Rosen
2002-08-28 20:27 ` Björn Lundin
[not found] <002a01c24e5f$9ee347b0$789a0844@robertqgx6k4x9>
2002-08-28 11:33 ` sk
[not found] ` <3D6CB4F5.F4E05D76@myob.com>
2002-08-28 11:37 ` sk
2002-08-28 15:39 ` Robert C. Leif
2002-08-28 18:53 ` Jeffrey Carter
2002-08-28 20:54 ` Robert C. Leif
2002-08-28 22:55 ` Robert A Duff
2002-08-29 3:18 ` Robert C. Leif
[not found] <005101c24ea9$0de9c960$789a0844@robertqgx6k4x9>
2002-08-28 16:06 ` sk
2002-08-28 22:44 ` tmoran
2002-08-29 0:37 ` tmoran
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox