comp.lang.ada
 help / color / mirror / Atom feed
From: Adam Beneschan <adambeneschan@gmail.com>
Subject: Re: Position of "use"
Date: Wed, 9 Jul 2014 08:14:26 -0700 (PDT)
Date: 2014-07-09T08:14:26-07:00	[thread overview]
Message-ID: <33fbd821-cb30-4be9-93c1-17002470413e@googlegroups.com> (raw)
In-Reply-To: <lpj5uo$kd1$1@speranza.aioe.org>

On Wednesday, July 9, 2014 3:36:09 AM UTC-7, an...@att.net wrote:

> For Ada compilers, where you can have more than one compilation_unit 
> within one file (RM 10.1 -- 10.1.1), it allows all preceding 
> compilation_unit to have access the same library with only one 
> "with_clause" without sharing global visibility to that package.
> 
> Note: GNAT limits the compilation_unit to one per file.  But GNAT still 
> allows this type of program design. Putting the "with_clause" in the 
> specification file (.ads) allows access for the corresponding body file 
> (.adb) in some cases without having the "with_clause" in the body file.

I'm not sure what you're trying to say here, but I want to reiterate: according to the Ada rules, putting multiple compilation units in the same file has *no* effect on the visibility rules (or any other rules).  If you have package specifications for two different packages, P1 and P2, in the same file, a "with" or "use" clause on P1 does not apply to P2, and vice versa.

A "with" clause on a specification of any package automatically applies to the body, and it also automatically applies to any child unit specifications or bodies.  This is due to the rules in RM 8.1 and has nothing to do with GNAT, and nothing to do with whether the specification and body are in the same file or not.

Thus, in this example, the comments are wrong:

> --
> --  compilation_unit 4 : Limits visibility to Text_IO to a 
> --                       "selected_component", unless the 
> --                       global "use_clause" is used.
> --
> --              example :  Text_IO.New_Line ;
> --
> package Test_Cal is
> --    ...
> end Test_Cal ;

Text_IO is not visible at all, since there is no "with Text_IO" on Test_Cal.  The "with Text_IO" earlier in the file, on "package Test_55", has no effect.

                          -- Adam

  reply	other threads:[~2014-07-09 15:14 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-07-05  6:43 Position of "use" Victor Porton
2014-07-05  7:12 ` J-P. Rosen
2014-07-07 16:45   ` Adam Beneschan
2014-07-07 17:08     ` Pascal Obry
2014-07-07 17:40       ` Peter Chapin
2014-07-07 19:17       ` Adam Beneschan
2014-07-08  5:26     ` J-P. Rosen
2014-07-08 15:32       ` Adam Beneschan
2014-07-08 19:30 ` Adam Beneschan
2014-07-08 22:39   ` Victor Porton
2014-07-09 10:36 ` anon
2014-07-09 15:14   ` Adam Beneschan [this message]
2014-07-10  1:27     ` anon
2014-07-10  9:50       ` AdaMagica
2014-07-10 13:10         ` J-P. Rosen
2014-07-10 15:57           ` Adam Beneschan
2014-07-10 17:47             ` Tero Koskinen
2014-07-10 19:15           ` Jeffrey Carter
2014-07-15  5:56         ` anon
2014-07-15  7:36           ` Georg Bauhaus
2014-07-15 17:01             ` Simon Wright
2014-07-15 17:23               ` Jeffrey Carter
2014-07-15 19:44                 ` Simon Wright
2014-07-15 17:47               ` G.B.
2014-07-15 17:51               ` Adam Beneschan
2014-07-15 20:04                 ` Simon Wright
2014-07-16  7:19                 ` anon
2014-07-10 15:54       ` Adam Beneschan
replies disabled

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