comp.lang.ada
 help / color / mirror / Atom feed
From: anon@att.net
Subject: Re: Position of "use"
Date: Thu, 10 Jul 2014 01:27:08 +0000 (UTC)
Date: 2014-07-10T01:27:08+00:00	[thread overview]
Message-ID: <lpkq5a$6ir$1@speranza.aioe.org> (raw)
In-Reply-To: 33fbd821-cb30-4be9-93c1-17002470413e@googlegroups.com

Actually, the comments for compilation_unit 4 are correct under multiple 
compilation_unit type files, which GNAT does not support. It was tested 
under AdaEd-1.11.0a compiled for SuSE Linux, before I posted a condensed 
version.

Note: GNAT (Adacore or GNU) does not support multiple 
compilation_unit (s) within one file. 

For multiple compilation_unit, likes those files found in ACVC, the 
external visibility starts with the "with_clause" and that clause 
grants all succeeding compilation_unit(s) access to that package or 
routine no matter how many compilation_unit there are. In other words 
you only need one "with_clause" for Ada compilers that support multiple 
compilation_unit in the same file. 

But the direct visibility is allowed by the "use_clause". Exception is 
where two or more routines from two sources are the same. 

Example is GNAT.IO.Put ( S : String ) and 
           Ada.Text_IO.Put ( Item : in String )

In this case the compiler requires help to link to the correct package 
with requires a "selected_component" type statement to correctly 
identify the correct routine.


Under Ada the following should work but some versions of GNAT over the 
years have not match the formal_parameter of two or more routines 
correctly when using two unique packages.

     Put ( S => <string> ) ;    -- GNAT.IO
     Put ( Item => <string> ) ; -- Ada.Text_IO

so it better just to use 

           GNAT.IO.Put ( <String> ) -- or
           Ada.Text_IO.Put ( <String> )
or

           GNAT.IO.Put ( S => <String> ) -- or
           Ada.Text_IO.Put ( Item => <String> )


In <33fbd821-cb30-4be9-93c1-17002470413e@googlegroups.com>, Adam Beneschan <adambeneschan@gmail.com> writes:
>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=20
>> within one file (RM 10.1 -- 10.1.1), it allows all preceding=20
>> compilation_unit to have access the same library with only one=20
>> "with_clause" without sharing global visibility to that package.
>>=20
>> Note: GNAT limits the compilation_unit to one per file.  But GNAT still=
>=20
>> allows this type of program design. Putting the "with_clause" in the=20
>> specification file (.ads) allows access for the corresponding body file=
>=20
>> (.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: accor=
>ding 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 f=
>ile, 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 specification=
>s 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=20
>> --                       "selected_component", unless the=20
>> --                       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 eff=
>ect.
>
>                          -- Adam


  reply	other threads:[~2014-07-10  1:27 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
2014-07-10  1:27     ` anon [this message]
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