* visibility of private incomplete types
@ 2004-10-28 12:03 Georg Bauhaus
2004-10-28 15:36 ` Martin Dowie
0 siblings, 1 reply; 11+ messages in thread
From: Georg Bauhaus @ 2004-10-28 12:03 UTC (permalink / raw)
hello,
is GNAT correct in compiling the following program
without complaints? (There is a complaint if the
function in the body of P is uncommented.)
package p is
package inner is
private
type TI;
end inner;
private
type TI_Ptr is access constant inner.TI;
end p;
package body p is
-----------
-- inner --
-----------
package body inner is
type TI is null record;
end inner;
-- function test return TI_Ptr is
-- begin
-- return new inner.TI;
-- end test;
end p;
with p;
procedure p_test is
begin null; end;
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: visibility of private incomplete types
2004-10-28 12:03 visibility of private incomplete types Georg Bauhaus
@ 2004-10-28 15:36 ` Martin Dowie
2004-10-28 22:19 ` Randy Brukardt
0 siblings, 1 reply; 11+ messages in thread
From: Martin Dowie @ 2004-10-28 15:36 UTC (permalink / raw)
Georg Bauhaus wrote:
> is GNAT correct in compiling the following program
> without complaints? (There is a complaint if the
> function in the body of P is uncommented.)
No - according to ObjectAda v 7.2.2
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: visibility of private incomplete types
2004-10-28 15:36 ` Martin Dowie
@ 2004-10-28 22:19 ` Randy Brukardt
2004-10-29 14:16 ` Nick Roberts
2004-10-30 0:36 ` Georg Bauhaus
0 siblings, 2 replies; 11+ messages in thread
From: Randy Brukardt @ 2004-10-28 22:19 UTC (permalink / raw)
"Martin Dowie" <martin.dowie@baesystems.com> wrote in message
news:4181108a_1@baen1673807.greenlnk.net...
> Georg Bauhaus wrote:
> > is GNAT correct in compiling the following program
> > without complaints? (There is a complaint if the
> > function in the body of P is uncommented.)
>
> No - according to ObjectAda v 7.2.2
Right, because the outer private part doesn't have visibility on the private
part of Inner. Only the body of Inner should be able to see TI.
Randy.
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: visibility of private incomplete types
2004-10-28 22:19 ` Randy Brukardt
@ 2004-10-29 14:16 ` Nick Roberts
2004-10-29 15:33 ` Frank J. Lhota
2004-10-30 0:36 ` Georg Bauhaus
1 sibling, 1 reply; 11+ messages in thread
From: Nick Roberts @ 2004-10-29 14:16 UTC (permalink / raw)
Randy Brukardt wrote:
>>>is GNAT correct in compiling the following program
>>>without complaints? (There is a complaint if the
>>>function in the body of P is uncommented.)
>>
>>No - according to ObjectAda v 7.2.2
>
> Right, because the outer private part doesn't have visibility on the
> private part of Inner. Only the body of Inner should be able to see
> TI.
Indeed.
Also, would I be right in saying that, in Ada 95, it is not permitted
for a type declared (by an incomplete type declaration) in the private
part of a package to be completed in the package's body?
Is this going to be permitted in Ada 2005?
--
Nick Roberts
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: visibility of private incomplete types
2004-10-29 14:16 ` Nick Roberts
@ 2004-10-29 15:33 ` Frank J. Lhota
2004-10-30 3:13 ` Nick Roberts
0 siblings, 1 reply; 11+ messages in thread
From: Frank J. Lhota @ 2004-10-29 15:33 UTC (permalink / raw)
"Nick Roberts" <nick.roberts@acm.org> wrote in message
news:2uf1loF27r1iqU1@uni-berlin.de...
> Randy Brukardt wrote:
> Also, would I be right in saying that, in Ada 95, it is not permitted
> for a type declared (by an incomplete type declaration) in the private
> part of a package to be completed in the package's body?
No, this was permitted as early as Ada 83, and I used this technique many
times. For example, assume that we are writing a package that implements
widgets. Widgets will be implemented as pointers to a record, but of course
we will hide this implementation detail using a private type. We can also
hide the structure of this record type as follows:
package Widgets is
type Widget_Type is limited private;
procedure Open( Widget : in out Widget_Type; Name : in String );
procedure Close( Widget : in out Widget_Type );
...
private
type Widget_Data;
type Widget_Type is access Widget_Data;
end Widget;
This type of package specification in legal in both Ada 83 and Ada 95 (and
presumably in Ada 200x), for Widget_Data is never used in a way that
requires a full declaration. Of course, Widget_Data must be fully declared
in the package body.
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: visibility of private incomplete types
2004-10-28 22:19 ` Randy Brukardt
2004-10-29 14:16 ` Nick Roberts
@ 2004-10-30 0:36 ` Georg Bauhaus
1 sibling, 0 replies; 11+ messages in thread
From: Georg Bauhaus @ 2004-10-30 0:36 UTC (permalink / raw)
Randy Brukardt <randy@rrsoftware.com> wrote:
: "Martin Dowie" <martin.dowie@baesystems.com> wrote in message
: news:4181108a_1@baen1673807.greenlnk.net...
:> Georg Bauhaus wrote:
:> > is GNAT correct in compiling the following program
:> > without complaints? (There is a complaint if the
:> > function in the body of P is uncommented.)
:>
:> No - according to ObjectAda v 7.2.2
:
: Right, because the outer private part doesn't have visibility on the private
: part of Inner. Only the body of Inner should be able to see TI.
Thanks.
(PR #18227)
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: visibility of private incomplete types
2004-10-29 15:33 ` Frank J. Lhota
@ 2004-10-30 3:13 ` Nick Roberts
2004-11-01 0:40 ` Dr. Adrian Wrigley
0 siblings, 1 reply; 11+ messages in thread
From: Nick Roberts @ 2004-10-30 3:13 UTC (permalink / raw)
Frank J. Lhota wrote:
>>Also, would I be right in saying that, in Ada 95, it is not permitted
>>for a type declared (by an incomplete type declaration) in the private
>>part of a package to be completed in the package's body?
>
> No, this was permitted as early as Ada 83, and I used this technique many
> times. For example, assume that we are writing a package that implements
> widgets. Widgets will be implemented as pointers to a record, but of course
> we will hide this implementation detail using a private type. We can also
> hide the structure of this record type as follows:
>
> package Widgets is
>
> type Widget_Type is limited private;
>
> procedure Open( Widget : in out Widget_Type; Name : in String );
> procedure Close( Widget : in out Widget_Type );
> ...
>
> private
>
> type Widget_Data;
> type Widget_Type is access Widget_Data;
>
> end Widget;
>
> This type of package specification in legal in both Ada 83 and Ada 95 (and
> presumably in Ada 200x), for Widget_Data is never used in a way that
> requires a full declaration. Of course, Widget_Data must be fully declared
> in the package body.
I have to laugh. I now recall that I have used this technique /myself/
in the past. What a memory! RM95 3.10.1 (3). Sorry.
--
Nick Roberts
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: visibility of private incomplete types
2004-10-30 3:13 ` Nick Roberts
@ 2004-11-01 0:40 ` Dr. Adrian Wrigley
2004-12-09 21:21 ` Lionel Draghi
0 siblings, 1 reply; 11+ messages in thread
From: Dr. Adrian Wrigley @ 2004-11-01 0:40 UTC (permalink / raw)
> Frank J. Lhota wrote:
...example omitted
>> This type of package specification in legal in both Ada 83 and Ada 95
>> (and presumably in Ada 200x), for Widget_Data is never used in a way
>> that requires a full declaration. Of course, Widget_Data must be fully
>> declared in the package body.
At last! An answer to a long-standing annoyance I found with the language...
how to put the full type declarations (implementations) into the package
body, where they belong!
I had thought it was meant to be possible, but had never seen exactly how.
(presumably this one way to get physical isolation between different
components in a large system, so changes to data types don't trigger
recompilation of everything)
time to tidy up some old code of mine...
Thanks for pointing this out, guys!
--
Adrian
(maybe I'd better also (re-)read the ARM and those books gathering dust...)
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: visibility of private incomplete types
2004-11-01 0:40 ` Dr. Adrian Wrigley
@ 2004-12-09 21:21 ` Lionel Draghi
2004-12-10 4:06 ` Alexander E. Kopilovich
2004-12-10 9:23 ` Martin Krischik
0 siblings, 2 replies; 11+ messages in thread
From: Lionel Draghi @ 2004-12-09 21:21 UTC (permalink / raw)
Dr. Adrian Wrigley a ï¿œcrit :
...
> At last! An answer to a long-standing annoyance I found with the language...
> how to put the full type declarations (implementations) into the package
> body, where they belong!
...
> (maybe I'd better also (re-)read the ARM and those books gathering
> dust...)
Wouldn't it be a good idea to start a wiki on Ada idioms and patterns to
gather those small to mid sized tips?
--
Lionel Draghi
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: visibility of private incomplete types
2004-12-09 21:21 ` Lionel Draghi
@ 2004-12-10 4:06 ` Alexander E. Kopilovich
2004-12-10 9:23 ` Martin Krischik
1 sibling, 0 replies; 11+ messages in thread
From: Alexander E. Kopilovich @ 2004-12-10 4:06 UTC (permalink / raw)
To: comp.lang.ada
Lionel Draghi wrote:
>Wouldn't it be a good idea to start a wiki on Ada idioms and patterns to
>gather those small to mid sized tips?
This is certainly the most heretical idea I have seen in comp.lang.ada for
several years! -;)
Alexander Kopilovich aek@vib.usr.pu.ru
Saint-Petersburg
Russia
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: visibility of private incomplete types
2004-12-09 21:21 ` Lionel Draghi
2004-12-10 4:06 ` Alexander E. Kopilovich
@ 2004-12-10 9:23 ` Martin Krischik
1 sibling, 0 replies; 11+ messages in thread
From: Martin Krischik @ 2004-12-10 9:23 UTC (permalink / raw)
Lionel Draghi wrote:
> Dr. Adrian Wrigley a ï¿œcrit :
> ...
>> At last! An answer to a long-standing annoyance I found with the
>> language... how to put the full type declarations (implementations) into
>> the package body, where they belong!
> ...
> > (maybe I'd better also (re-)read the ARM and those books gathering
> > dust...)
>
> Wouldn't it be a good idea to start a wiki on Ada idioms and patterns to
> gather those small to mid sized tips?
Well, what are you waiting for:
http://en.wikibooks.org/w/wiki.phtml?title=Programming:Ada:Tips&action=edit
The good thing about wiki is that you don't need to wait for somebody else.
Martin
--
mailto://krischik@users.sourceforge.net
http://www.ada.krischik.com
^ permalink raw reply [flat|nested] 11+ messages in thread
end of thread, other threads:[~2004-12-10 9:23 UTC | newest]
Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-10-28 12:03 visibility of private incomplete types Georg Bauhaus
2004-10-28 15:36 ` Martin Dowie
2004-10-28 22:19 ` Randy Brukardt
2004-10-29 14:16 ` Nick Roberts
2004-10-29 15:33 ` Frank J. Lhota
2004-10-30 3:13 ` Nick Roberts
2004-11-01 0:40 ` Dr. Adrian Wrigley
2004-12-09 21:21 ` Lionel Draghi
2004-12-10 4:06 ` Alexander E. Kopilovich
2004-12-10 9:23 ` Martin Krischik
2004-10-30 0:36 ` Georg Bauhaus
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox