comp.lang.ada
 help / color / mirror / Atom feed
* Visibility
@ 1992-12-23 23:35 agate!spool.mu.edu!uwm.edu!cs.utexas.edu!torn!nott!netfs!news
  0 siblings, 0 replies; 14+ messages in thread
From: agate!spool.mu.edu!uwm.edu!cs.utexas.edu!torn!nott!netfs!news @ 1992-12-23 23:35 UTC (permalink / raw)


I have a quesiton on Visiblity. The following Ada code
generates the following error.


     package datatypes is
         subtype widget is integer;
     end datatypes;

     with datatypes;
     package testvisibility is
         function widget (a: integer) return datatypes.widget;
     end testvisibility;



     $ ada testviz
         7       function widget (a: integer) return datatypes.widget;
     .........................................................1
     %ADAC-E-NOTDECLALLHIDER, (1) All declarations with designator widget are
             globally hidden by function specification widget at line 7 [LRM 8.
3(16)]
     %ADAC-E-ERRPROCESS, Errors compiling package specification testvisibility 
in
             file FLD$CENTRAL:[BERRYMAN.MFP.MOTIF]TESTVIZ.ADA;4
     %ADAC-E-ENDDIAGS, Ada compilation completed with 1 diagnostic



I can see why this would have happened if I'd coded:

     with datatypes; USE DATATYPES;
     package testvisibility is
         function widget (a: integer) return widget;
     end testvisibility;


But since I have a full specification for DATATYPES.WIDGET
why is there a problem???


Don Berryman
Defence Research Establishment Pacific
Canadian Forces Base Esquimalt
Victoria, BC, CANADA, V0S-1B0
604-363-2731    604-363-2856fax
berryman@orca.drep.dnd.ca

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: Visibility
@ 1992-12-24  2:16 Richard Pattis
  0 siblings, 0 replies; 14+ messages in thread
From: Richard Pattis @ 1992-12-24  2:16 UTC (permalink / raw)


In article <1992Dec23.233519.21523@netfs.dnd.ca> BERRYMAN@orca.drep.dnd.ca (DON
 BERRYMAN) writes:
>
>
>I have a quesiton on Visiblity. The following Ada code
>generates the following error.
>
>
>     package datatypes is
>         subtype widget is integer;
>     end datatypes;
>
>     with datatypes;
>     package testvisibility is
>         function widget (a: integer) return datatypes.widget;
>     end testvisibility;
>

The LRM says in 8.3(16) "every declaration with the same designator" is
hidden. And designators are only identifiers or operator symbols. So it looks
like your designator widget, even when declared in another package and
selected, is still hidden.  There are two notes on this, but both involve
generics

Now, can anyone say why this interpretation "is a good thing".

Rich Pattis


-- 
------------------------------------------------------------------------------
  Richard E. Pattis                     "Programming languages are like
  Department of Computer Science         pizzas - they come in only "too"
    and Engineering                      sizes: too big and too small."

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: Visibility
@ 1992-12-24 11:48 agate!spool.mu.edu!darwin.sura.net!Sirius.dfn.de!chx400!sicsun!disuns2!lg
  0 siblings, 0 replies; 14+ messages in thread
From: agate!spool.mu.edu!darwin.sura.net!Sirius.dfn.de!chx400!sicsun!disuns2!lg @ 1992-12-24 11:48 UTC (permalink / raw)


In article <1992Dec24.021655.22555@beaver.cs.washington.edu>, pattis@cs.washing
ton.edu (Richard Pattis) writes:
|> In article <1992Dec23.233519.21523@netfs.dnd.ca> BERRYMAN@orca.drep.dnd.ca (
DON BERRYMAN) writes:
|> >
|> >
|> >I have a quesiton on Visiblity. The following Ada code
|> >generates the following error.
|> >
|> >
|> >     package datatypes is
|> >         subtype widget is integer;
|> >     end datatypes;
|> >
|> >     with datatypes;
|> >     package testvisibility is
|> >         function widget (a: integer) return datatypes.widget;
|> >     end testvisibility;
|> >
|> 
|> The LRM says in 8.3(16) "every declaration with the same designator" is
|> hidden. And designators are only identifiers or operator symbols. So it look
s
|> like your designator widget, even when declared in another package and
|> selected, is still hidden.  There are two notes on this, but both involve
|> generics
|> 
|> Now, can anyone say why this interpretation "is a good thing".
|> 
|> Rich Pattis
|> 

I think the rule is intended as the simplest way of preventing someone
from writing the following:

function widget (A : integer := widget) return integer;

This prevents the compiler from having to figure out what the designator
corresponds to and whether or not it should be legal. The above code
obviously won't work but how about:

function widget (A : integer := widget(1)) return integer;

I think they wanted to avoid all these legalistic problems and so they
just came up with the simplest rule possible that eliminated the problem.
If people think that Ada is hairy now they should just imagine if it had
rules like:

Within the specification of a function, every declaration with the same 
designator as the function that is found as a default value in the
parameter list is hidden; ...

I would think rules like this would be a compiler writers nightmare.

Robb Nebbe
nebbe@lglsun.epfl.ch

^ permalink raw reply	[flat|nested] 14+ messages in thread

* visibility
@ 2003-06-04 22:12 And838N
  2003-06-05 10:35 ` visibility Preben Randhol
  2003-06-05 15:19 ` visibility Frank J. Lhota
  0 siblings, 2 replies; 14+ messages in thread
From: And838N @ 2003-06-04 22:12 UTC (permalink / raw)
  To: comp.lang.ada

Ok, here's another question.  I'll provide some background information first.

Let us say that there is a procedure in an .adb file that is not in a 
package and it looks something like the following:

----------------------
with
ada.text_io,
ada.integer_text_io,
ada.strings.unbounded;

use
ada.text_io,
ada.integer_text_io,
ada.strings.unbounded;

procedure x is
    astring: unbounded_string := "hello world";
    somenumber: integer := 0;
begin
    somenumber := count(astring, to_set(' '));
    put(somenumber); 
end x;
-----------------------

Now we go compile it and GNAT gives me a message that says there is 
more than one "count" and that I have to specify, by using the full 
package name before the word count, in order to specify which count I
want.  Which isn't so bad, yet...

So out of curiosity I look at the version of count inside ada.text_io 
and compare it to the version of count inside ada.strings.unbounded.  
Turns out the count inside ada.text_io isn't a "procedure" at all, it's 
a variable type.

So I investigate further.  The author of Ada as a second language, 
Norman Cohen provided a chapter on scope and visiblity.  In that 
chapter (actually an appendix), he says that one of the only times 
there will be a visibility problem is when a variable type and a 
procedure have the same name.  

It is hard for me to accept that Ada (GNAT) can't tell the difference 
between a variable type and a procedure?  I wouldn't be surprised if 
both counts were procedures or both counts were variable types, having the same "signature".  But a variable type compared to a procedure?  
Does that mean that after a visibility conflict occurs when compiling 
that there is no "signature" checking? Can someone please explain?

Second question related to "with"ing and "use"ing. (I think the first
question might be resolved by re-working my "with"s and "use"s.)
If I "with" ada.strings, that makes it, and it's children "visible" to
my procedure or package?
If so, then I can "use" only the children I want, like fixed, 
unbounded, unbounded_text_io, etcetera?
If so, does the compiler or linker still link in, or for lack of a 
better term "insert" code into my procedure/package for the children I 
didn't "use"?

Thanks,

Andrew

P.S.
How's the word wrap now?



__________________________________________________________________
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



^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: visibility
  2003-06-04 22:12 visibility And838N
@ 2003-06-05 10:35 ` Preben Randhol
  2003-06-05 15:19 ` visibility Frank J. Lhota
  1 sibling, 0 replies; 14+ messages in thread
From: Preben Randhol @ 2003-06-05 10:35 UTC (permalink / raw)


And838N@netscape.net wrote:
> Ok, here's another question.  I'll provide some background information first.
> 
> Let us say that there is a procedure in an .adb file that is not in a 
> package and it looks something like the following:
> 
> ----------------------
> with
> ada.text_io,
> ada.integer_text_io,
> ada.strings.unbounded;
> 
> use
> ada.text_io,
> ada.integer_text_io,
> ada.strings.unbounded;
> 
> procedure x is
>     astring: unbounded_string := "hello world";
                                   ^^^^^^^^^^^^^
                                   Don't you have to write:
                                   To_Unbounded_String ("hello world");
>     somenumber: integer := 0;
> begin
>     somenumber := count(astring, to_set(' '));
>     put(somenumber); 
      
      Put (Integer'Image(somenumber));

Then you don't need: ada.integer_text_io
      
> end x;
> -----------------------
> It is hard for me to accept that Ada (GNAT) can't tell the difference 
> between a variable type and a procedure?  I wouldn't be surprised if 

But in your example it is not a procedure, but a function.

> Second question related to "with"ing and "use"ing. (I think the first
> question might be resolved by re-working my "with"s and "use"s.)

General rule, with but don't use :-) Well that of course depends on the
programmer. If you are new to Ada it is better not to use. Never use
your own Package at least. I find that very nice as then I know which
package the procedure or function is in when I look over the code or I'm
trying to fix an error.

-- 
Preben Randhol                    http://www.pvv.org/~randhol/



^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: visibility
       [not found] <666191F6.00B406DF.0015D3EC@netscape.net>
@ 2003-06-05 15:16 ` David C. Hoos
  0 siblings, 0 replies; 14+ messages in thread
From: David C. Hoos @ 2003-06-05 15:16 UTC (permalink / raw)
  To: And838N, comp.lang.ada


----- Original Message ----- 
From: <And838N@netscape.net>
To: <comp.lang.ada@ada.eu.org>
Sent: Wednesday, June 04, 2003 5:12 PM
Subject: visibility


> Ok, here's another question.  I'll provide some background information
first.
>
> Let us say that there is a procedure in an .adb file that is not in a
> package and it looks something like the following:
>
> ----------------------
> with
> ada.text_io,
> ada.integer_text_io,
> ada.strings.unbounded;
>
> use
> ada.text_io,
> ada.integer_text_io,
> ada.strings.unbounded;
>
> procedure x is
>     astring: unbounded_string := "hello world";
>     somenumber: integer := 0;
> begin
>     somenumber := count(astring, to_set(' '));
>     put(somenumber);
> end x;
> -----------------------
>
> Now we go compile it and GNAT gives me a message that says there is
> more than one "count" and that I have to specify, by using the full
> package name before the word count, in order to specify which count I
> want.  Which isn't so bad, yet...

First of all, gnat dows not report what you said it reports; here's the
actual report:
x.adb:12:34: expected private type "Ada.Strings.Unbounded.Unbounded_String"
x.adb:12:34: found a string type
x.adb:15:19: "count" is not visible
x.adb:15:19: multiple use clauses cause hiding
x.adb:15:19: hidden declaration at a-strunb.ads:217
x.adb:15:19: hidden declaration at a-strunb.ads:211
x.adb:15:19: hidden declaration at a-strunb.ads:205
x.adb:15:19: hidden declaration at a-textio.ads:66
x.adb:15:34: "to_set" is not visible
x.adb:15:34: non-visible declaration at a-strmap.ads:107
x.adb:15:34: non-visible declaration at a-strmap.ads:105
x.adb:15:34: non-visible declaration at a-strmap.ads:70
x.adb:15:34: non-visible declaration at a-strmap.ads:68

As is usual, the gnat error messages are very clear and precise.  You
need to eliminate the errors in order.  Changing the declaration of
"astring" to a correct one soves that problem.  E.g. change it to:

astring: Unbounded_String := To_Unbounded_String ("hello world");

Ada does not do implicit conversions -- i.e. it does not "automagically"
do things behind the scenes that might not be what you intended.

The second error -- the invisibility of "count" is discussed below.

The third error -- the invisibility of "to_set" is corrected by including
"ada.strings.maps" in your "with" and "use" clauses.
>
> So out of curiosity I look at the version of count inside ada.text_io
> and compare it to the version of count inside ada.strings.unbounded.
> Turns out the count inside ada.text_io isn't a "procedure" at all, it's
> a variable type.

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".

>
> So I investigate further.  The author of Ada as a second language,
> Norman Cohen provided a chapter on scope and visiblity.  In that
> chapter (actually an appendix), he says that one of the only times
> there will be a visibility problem is when a variable type and a
> procedure have the same name.

I could find no such statement on my copy of Cohen's book.

He does say that "hiding" should be avoided, so you should have heeded the
compiler message.

>
> It is hard for me to accept that Ada (GNAT) can't tell the difference
> between a variable type and a procedure?  I wouldn't be surprised if
> both counts were procedures or both counts were variable types, having the
same "signature".  But a variable type compared to a procedure?
The "count" you are using in your program is not a procedure; it's a
function.
The "count" in Ada.Text_IO is a type (there's no such thing as a "variable
type" in Ada.
Ada types can be used to declare constants as well as variables.

When a type name appears after ":=" -- i.e., in an expression -- the
compiler would
think it was a type conversion.  Type conversions have the same syntax as a
function call.

> Does that mean that after a visibility conflict occurs when compiling
> that there is no "signature" checking? Can someone please explain?
>
> Second question related to "with"ing and "use"ing. (I think the first
> question might be resolved by re-working my "with"s and "use"s.)
> If I "with" ada.strings, that makes it, and it's children "visible" to
> my procedure or package?

No. The children are not visible. You must explicitly "with" the children
you will use.

> If so, then I can "use" only the children I want, like fixed,
> unbounded, unbounded_text_io, etcetera?

There is no such unit as "unbounded_text_io" in the Ada standard libraries.

> If so, does the compiler or linker still link in, or for lack of a
> better term "insert" code into my procedure/package for the children I
> didn't "use"?

"Use" clauses affect only visibility; they have no effect on linking.
All compilation units "withed" are linked into the executable, regardless of
whether
they are referenced in your program.
>
> Thanks,
>
> Andrew
>
> P.S.
> How's the word wrap now?
>
>
>
> __________________________________________________________________
> 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
>




^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: visibility
  2003-06-04 22:12 visibility And838N
  2003-06-05 10:35 ` visibility Preben Randhol
@ 2003-06-05 15:19 ` Frank J. Lhota
  1 sibling, 0 replies; 14+ messages in thread
From: Frank J. Lhota @ 2003-06-05 15:19 UTC (permalink / raw)


First of all, the Count entity in the Ada.Strings.Unbounded is a function,
not a procedure. There can be name conflicts between type names and function
names, because an Ada type conversion uses the function notation. For
example, if we have

    X : Ada.Text_Io.Count;
    Y : Some_Numeric_Type_Other_Than_Count;

then the was you would convert Y for assignment to X is

    X := Ada.Text_Io.Count( Y );

This is probably the source of the compiler's confusion. The solution is
obvious: qualify this occurence of Count so that the compiler, as well as
the humans reading your code, will know which Count you are referring to.





^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: Visibility
@ 2003-06-06  5:15 christoph.grein
  0 siblings, 0 replies; 14+ messages in thread
From: christoph.grein @ 2003-06-06  5:15 UTC (permalink / raw)
  To: comp.lang.ada

>     package datatypes is
>         subtype widget is integer;
>     end datatypes;
>
>     with datatypes;
>     package testvisibility is
>         function widget (a: integer) return datatypes.widget;
>     end testvisibility;

Did no one realize that this is an Ada83 restriction? In Ada95, this code is 
correct.

RM83 8.3(16) vs. RM95 8.3(14..23)



^ permalink raw reply	[flat|nested] 14+ messages in thread

* Visibility
@ 2003-06-07  8:21 And838N
  2003-06-07 17:29 ` Visibility Jeffrey Carter
  0 siblings, 1 reply; 14+ messages in thread
From: And838N @ 2003-06-07  8:21 UTC (permalink / raw)
  To: comp.lang.ada

>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.
 
>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.

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.

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



^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: Visibility
       [not found] <009C830A.36D4A463.0015D3EC@netscape.net>
@ 2003-06-07 12:18 ` David C. Hoos, Sr.
  2003-06-08  3:28   ` Visibility Hyman Rosen
  0 siblings, 1 reply; 14+ messages in thread
From: David C. Hoos, Sr. @ 2003-06-07 12:18 UTC (permalink / raw)
  To: And838N, comp.lang.ada


----- 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
> 
> 




^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: Visibility
  2003-06-07  8:21 Visibility And838N
@ 2003-06-07 17:29 ` Jeffrey Carter
  0 siblings, 0 replies; 14+ messages in thread
From: Jeffrey Carter @ 2003-06-07 17:29 UTC (permalink / raw)


And838N@netscape.net wrote:
> 
> 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
> 
> 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.

This message does not say that GNAT cannot resolve which Count you mean. 
It says that, according to the rules of the language, Count is not 
visible because multiple use causes cause hiding. The language requires 
that the compiler not resolve this use of Count.

In some other hypothetical language (let's call it Dad) the compiler may 
be allowed to resolve any such issues that it can, and only complain 
about those it cannot resolve. That would be perfectly fine for Dad, but 
not for Ada, because Ada strives for portability. If the language does 
not define what kinds of things the compiler may resolve, then different 
compilers may give different results on the same source, with one 
compiler resolving such an issue while another cannot.

> 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". 

Context clauses ("with") have nothing to do with files. The things named 
in context clauses are compilation units. There is no correlation 
between compilation units and files in the language (GNAT enforces such 
a correlation because of its compilation model, but that's an 
implementation rule, not a language rule).

The "with" makes the compilation unit visible. If the compilation unit 
is a package, one may use dot notation to refer to the declarations in 
its visible part. The "use" makes the declarations in a package's 
visible part directly visible, except where it causes hiding, in which 
case it does not.

-- 
Jeff Carter
"I would never want to belong to any club that
would have someone like me for a member."
Annie Hall




^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: Visibility
  2003-06-07 12:18 ` Visibility David C. Hoos, Sr.
@ 2003-06-08  3:28   ` Hyman Rosen
  2003-06-08 10:20     ` Visibility Frank J. Lhota
  0 siblings, 1 reply; 14+ messages in thread
From: Hyman Rosen @ 2003-06-08  3:28 UTC (permalink / raw)


David C. Hoos, Sr. wrote:
> 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.

Only at program startup?




^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: Visibility
  2003-06-08  3:28   ` Visibility Hyman Rosen
@ 2003-06-08 10:20     ` Frank J. Lhota
  2003-06-08 16:18       ` Visibility Robert I. Eachus
  0 siblings, 1 reply; 14+ messages in thread
From: Frank J. Lhota @ 2003-06-08 10:20 UTC (permalink / raw)


"Hyman Rosen" <hyrosen@mail.com> wrote in message
news:73yEa.45788$ca5.30987@nwrdny02.gnilink.net...
> David C. Hoos, Sr. wrote:
> > 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.
>
> Only at program startup?

Yes, only at startup. By the time that the main procedure starts execution,
everything it uses is elaborated.






^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: Visibility
  2003-06-08 10:20     ` Visibility Frank J. Lhota
@ 2003-06-08 16:18       ` Robert I. Eachus
  0 siblings, 0 replies; 14+ messages in thread
From: Robert I. Eachus @ 2003-06-08 16:18 UTC (permalink / raw)


Frank J. Lhota wrote:

> Yes, only at startup. By the time that the main procedure starts execution,
> everything it uses is elaborated.

It is highly unlikely that anyone will accidently create a program which 
fails an Elaboration_Check after the main program begins execution.  But 
there is a lot of elaboration that happens after the main program has 
started.  Consider for example a task type.  Its declaration is 
elaborated when the declarative part it appears in is elaborated, 
usually before the execution of the main program begins.  But 
elaboration of the object of the task type occurs after it is created, 
which could occur as the result of an allocator:

     Bar: Task_Access;
...
     Bar := new Some_Task;

If this is the first creation of an object of type Some_Task, and the 
elaboration of Some_Task fails an elaboaration check, the allocation 
will fail.




^ permalink raw reply	[flat|nested] 14+ messages in thread

end of thread, other threads:[~2003-06-08 16:18 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <009C830A.36D4A463.0015D3EC@netscape.net>
2003-06-07 12:18 ` Visibility David C. Hoos, Sr.
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

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