comp.lang.ada
 help / color / mirror / Atom feed
From: "David C. Hoos, Sr." <david.c.hoos.sr@ada95.com>
To: <And838N@netscape.net>, <comp.lang.ada@ada.eu.org>
Subject: Re: Visibility
Date: Sat, 7 Jun 2003 07:18:58 -0500
Date: 2003-06-07T07:18:58-05:00	[thread overview]
Message-ID: <mailman.3.1054988387.1173.comp.lang.ada@ada.eu.org> (raw)
In-Reply-To: 009C830A.36D4A463.0015D3EC@netscape.net


----- Original Message ----- 
From: <And838N@netscape.net>
To: <comp.lang.ada@ada.eu.org>
Sent: June 07, 2003 3:21 AM
Subject: Visibility


> >Why did you "with" and "use" ada.text_io, when your program doesn't 
> >need them?  Elimination of this error solves the problem of visibility 
> >of "count". 
> Well, if I don't "with" ada.text_io I get the following message from
> gnatmake.
> iotest.adb:4:09: "put_line" is undefined
> iotest.adb:4:09: possible missing with of Text_IO
> iotest.adb:4:10: "put" is undefined
> iotest.adb:4:10: possible missing with of Text_IO
> hence, the reason I "withed" text_io.
> 
If you look at your original post (on June 4), there was no "put_line"
statement -- hence, the reason for my question 
> >I could find no such statement on my copy of Cohen's book. 
> Page 1039, Section A.2
> 
> >There is no such unit as "unbounded_text_io" in the Ada standard
> >libraries. 
> Hmmm...I have a "with" for Ada.strings.unbounded.text_io and the file 
> in <libdirectory>/adainclude/a-suteio.ads (using gcc-lib) says
> otherwise.  The package that has the Count function I am talking about
> is ada.strings.unbounded.
> 
> According to Cohen and obviously GNAT, the Count variable in text_io
> and the function with the same name from unbounded are visible in the
> same place, and for some reason it, GNAT, does not "determine" or maybe
> cannot determine which one to use by "signature".  To me, if anything,
> GNAT should have said something to the effect that I was trying to
> perform some sort of narrowing conversion rather than telling me that
> it did not know which Count to use because of a visibility issue.

First, Ada.Text_IO.Count is a _type_, not a variable as you state above.
Secondly, GNAT did _not_ tell you it didn't know which one to use.  It
told you (clearly and correctly) that multiple "use" clauses cause hiding,
which is correct according to the visibility rules. 
> 
> with
> ada.strings.unbounded,
> ada.text_io,
> ada.strings.maps;
> 
> use
> ada.strings.unbounded,
> ada.text_io,
> ada.strings.maps;
> 
> procedure visibilitytest is
>         astring: string := "hello world";
>         somenumber: integer;
> begin
>         put_line(astring);
>         somenumber := count(to_unbounded_string(astring), to_set(' '));
>         put_line(Integer'image(somenumber));
> end visibilitytest;
> 
> This code does not compile first because of a visibility issue.  The
> compiler output, gnatmake visibilitytest.adb -gnatf, yields:
> adagcc -c -gnatf visibilitytest.adb
> visibilitytest.adb:18:23: "count" is not visible
> visibilitytest.adb:18:23: multiple use clauses cause hiding
> visibilitytest.adb:18:23: hidden declaration at a-textio.ads:66
> visibilitytest.adb:18:23: hidden declaration at a-strunb.ads:217
> visibilitytest.adb:18:23: hidden declaration at a-strunb.ads:211
> visibilitytest.adb:18:23: hidden declaration at a-strunb.ads:205
> gnatmake: "visibilitytest.adb" compilation error
> 
> The fix is to specify which one to use on line 18.
> somenumber := ada.strings.unbounded.count(to_unbounded_string(as
> tring), to_set(' '));.  To me, GNAT should be able to resolve which
> count to use because the count in ada.strings.unbounded is a function
> and count in ada.text_io is a type.  Not to mention the function
> returns (or is of type) Natural, not count.
> 
> The answer to my question was in Cohen's book, chapter 10.  The 
> rules for the "with" clause and packages are to make a large 
> number of files easier to manage and to make it clear to the reader
> what is going on with any particular file.  The "with" clause just
> makes "stuff" visible; it is up to the programmer/engineer to specify
> or clarify, by using an expanded name, what facilities they are "use"
> ing from a particular package.  Thus, GNAT's compiler message tells
> me not that GNAT can't determine which count to use but that I need
> to specify, for future readers, which count I needed.  In doing so
> ,if I am searching for count, I narrow the search to the exact 
> package I need to look in for the count I "used". 
> 
> I'll be looking into Elaboration next.  It sounds to me like the 
> elaboration of a package is like the instantiation of a C++ class.
> If that's true, then I should be able to have multiple elaborations
> of a package that all have different values for their data members.
> And if that is true, then I've been using the package the wrong way.

Elaboration is nothing at all like the instantiation of a C++ class.
Elaboration is a _process_ that takes place at program startup wherein
declarations are executed -- e.g. to initialize a constant or variable.

Suppose you had the following declarations in the specification of a
package named my_pkg:

angle : Long_Float := 13.0;
base : Long_Float := 1234.5;
package Long_Float_Elementary_Functions is new
   Ada.Numerics.Generic_Elementary_Functions (Long_Float);
use Long_Float_Elementary_Functions;
altitude : Long_Float := base * Sin (angle * Ada.Numerics.Pi / 180.0);

Using the GNAT compiler, the object file resulting from the compilation
of your package would contain a procedure named my_pkg___elabs.

That procedure contains the elaboration code for your package
specification.

When compiling your main program, the compiler will insert code to
call that elaboration procedure as well as the elaboration procedures
of all of the compilation units making up your program.

_That's_ what elaboration is.

> 
> Thanks for the help all.
> 
> Andrew
> 
> __________________________________________________________________
> McAfee VirusScan Online from the Netscape Network.
> Comprehensive protection for your entire computer. Get your free trial today!
> http://channels.netscape.com/ns/computing/mcafee/index.jsp?promo=393397
> 
> Get AOL Instant Messenger 5.1 free of charge.  Download Now!
> http://aim.aol.com/aimnew/Aim/register.adp?promo=380455
> _______________________________________________
> comp.lang.ada mailing list
> comp.lang.ada@ada.eu.org
> http://ada.eu.org/mailman/listinfo/comp.lang.ada
> 
> 




       reply	other threads:[~2003-06-07 12:18 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <009C830A.36D4A463.0015D3EC@netscape.net>
2003-06-07 12:18 ` David C. Hoos, Sr. [this message]
2003-06-08  3:28   ` Visibility Hyman Rosen
2003-06-08 10:20     ` Visibility Frank J. Lhota
2003-06-08 16:18       ` Visibility Robert I. Eachus
2003-06-07  8:21 Visibility And838N
2003-06-07 17:29 ` Visibility Jeffrey Carter
  -- strict thread matches above, loose matches on Subject: below --
2003-06-06  5:15 Visibility christoph.grein
     [not found] <666191F6.00B406DF.0015D3EC@netscape.net>
2003-06-05 15:16 ` visibility David C. Hoos
2003-06-04 22:12 visibility And838N
2003-06-05 10:35 ` visibility Preben Randhol
2003-06-05 15:19 ` visibility Frank J. Lhota
1992-12-24 11:48 Visibility agate!spool.mu.edu!darwin.sura.net!Sirius.dfn.de!chx400!sicsun!disuns2!lg
1992-12-24  2:16 Visibility Richard Pattis
1992-12-23 23:35 Visibility agate!spool.mu.edu!uwm.edu!cs.utexas.edu!torn!nott!netfs!news
replies disabled

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