From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-0.3 required=5.0 tests=BAYES_00,FREEMAIL_FROM, REPLYTO_WITHOUT_TO_CC autolearn=no autolearn_force=no version=3.4.4 Path: eternal-september.org!reader01.eternal-september.org!reader02.eternal-september.org!news.eternal-september.org!news.eternal-september.org!news.eternal-september.org!feeder.eternal-september.org!aioe.org!.POSTED!not-for-mail From: anon@att.net Newsgroups: comp.lang.ada Subject: Re: Position of "use" Date: Wed, 9 Jul 2014 10:36:09 +0000 (UTC) Organization: Aioe.org NNTP Server Message-ID: References: Reply-To: anon@att.net NNTP-Posting-Host: E0IzzVonjr1ioUJkTs0GPw.user.speranza.aioe.org X-Complaints-To: abuse@aioe.org X-Notice: Filtered by postfilter v. 0.8.2 X-Newsreader: IBM NewsReader/2 2.0 Xref: news.eternal-september.org comp.lang.ada:20825 Date: 2014-07-09T10:36:09+00:00 List-Id: Using a global "use_clause" can sometime cause the compiler to hide all routines of one or more libraries. It is better to place most use_clause in a local routine or within the declare section of a block_statement. -- -- Example File: Test_2.adb -- -- Showing where compiler could hide visibility access to packages. -- with Ada.Text_IO ; -- There are a number of routines that are with GNAT.IO ; -- common in both packages so, placement of -- the use_clause is critical, if used. procedure body Test_2 is -- Both Ada.Text_IO and GNAT.IO packages must be access by using -- "selected_component" at this point procedure Test_2b is use GNAT.IO ; -- Grants global visibility to package GNAT.IO. but -- limits Ada.Text_IO to a "selected_component" -- access begin null ; end ; -- Allow all following routines will have visibility to -- Ada.Text_IO could also cause visibility problems with other -- packages. use Ada.Text_IO ; procedure Test_2a is use GNAT.IO ; -- Will cause the compiler to hide packages, -- so in this example any reference must be by -- "selected_component" for both Ada.Text_IO -- and GNAT.IO packages begin null ; end ; begin null ; end ; 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. -- -- Example of a multiple compilation_unit File: Test_Lib.ada -- -- Showing different access/visibility to package Text_IO -- -- compilation_unit 1 : Access to Text_IO is forbidden in this -- package package Test_Init is -- ... end Test_Init ; -- with Text_IO ; -- Access is Allowed -- use Text_IO ; -- Visibility would be global to all -- -- specification and body units if this -- -- statement is used. -- -- compilation_unit 2 : Limits visibility to Text_IO to a -- "selected_component", unless the -- global "use_clause" is used. -- -- example : Text_IO.Col -- package Test_55 is procedure Init ; -- ... end Test_55 ; -- -- -- compilation_unit 3 : Visibility of package depend upon -- placement of the "use_clause" -- package body Test_55 is -- use Text_IO ; -- Visibility is global within this package body procedure Init is use Text_IO ; -- Visibility is local to procedure begin Set_Col ( 5 ) ; Set_Line ( 2 ) ; end Init ; procedure Error is begin declare use Text_IO ; -- Visibility is local to this block statement begin Put ( "Error" ) ; end ; end Error ; -- ... end Test_55 ; -- -- -- 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 ; In , Victor Porton writes: >What is the difference between > >with X; use X; >package Y is >end Y; > >and > >with X; >package Y is > use X; >end Y; > >? > >-- >Victor Porton - http://portonvictor.org