* with and use
@ 2002-07-10 13:00 David Rasmussen
2002-07-10 13:25 ` Jean-Pierre Rosen
0 siblings, 1 reply; 7+ messages in thread
From: David Rasmussen @ 2002-07-10 13:00 UTC (permalink / raw)
First of all, what does this message from GNAT mean:
"with" can only appear in context clause
?
Secondly, where is with and use typically used, and what is the
difference between them?
/David
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: with and use
2002-07-10 13:00 with and use David Rasmussen
@ 2002-07-10 13:25 ` Jean-Pierre Rosen
2002-07-10 13:45 ` David Rasmussen
0 siblings, 1 reply; 7+ messages in thread
From: Jean-Pierre Rosen @ 2002-07-10 13:25 UTC (permalink / raw)
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 1086 bytes --]
"David Rasmussen" <pinkfloydhomer@yahoo.com> a �crit dans le message news: 3D2C2FF9.4020300@yahoo.com...
> First of all, what does this message from GNAT mean:
>
> "with" can only appear in context clause
>
A context clause is a clause that appears *before* a compilation unit. A with clause cannot appear *inside* anything else, so this
basically means that you have to move the with clause on top of the unit.
> Secondly, where is with and use typically used, and what is the
> difference between them?
>
A with clause means that a compilation unit needs the services from another *compilation unit* (i.e. a package, subprogram or
generic which is separately compiled).
A use clause factors out a *package*, i.e. you don't have to repeat the package name in front of every element.
Since a package can (but needs not) be a compilation unit, there are cases where both clauses can be applied, but they are really
orthogonals.
--
---------------------------------------------------------
J-P. Rosen (rosen@adalog.fr)
Visit Adalog's web site at http://www.adalog.fr
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: with and use
2002-07-10 13:25 ` Jean-Pierre Rosen
@ 2002-07-10 13:45 ` David Rasmussen
2002-07-10 14:24 ` Jean-Pierre Rosen
2002-07-10 17:18 ` Jeffrey D. Cherry
0 siblings, 2 replies; 7+ messages in thread
From: David Rasmussen @ 2002-07-10 13:45 UTC (permalink / raw)
Jean-Pierre Rosen wrote:
> "David Rasmussen" <pinkfloydhomer@yahoo.com> a �crit dans le message
> news: 3D2C2FF9.4020300@yahoo.com...
>
>> First of all, what does this message from GNAT mean:
>>
>> "with" can only appear in context clause
>>
>
> A context clause is a clause that appears *before* a compilation
> unit. A with clause cannot appear *inside* anything else, so this
> basically means that you have to move the with clause on top of the
> unit.
>
Thanks!
>
>> Secondly, where is with and use typically used, and what is the
>> difference between them?
>>
>
> A with clause means that a compilation unit needs the services from
> another *compilation unit* (i.e. a package, subprogram or generic
> which is separately compiled).
>
> A use clause factors out a *package*, i.e. you don't have to repeat
> the package name in front of every element. Since a package can (but
> needs not) be a compilation unit, there are cases where both clauses
> can be applied, but they are really orthogonals.
>
So with corresponds roughly to an #include of some header file that
defines prototypes etc. for some other compilation unit in C++, and use
corresponds roughly to "using namespace Whatever", assuming that the
things included were in a seperate namespace?
"with" and only appear at the top of a unit. Where can "use" appear?
/David
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: with and use
2002-07-10 13:45 ` David Rasmussen
@ 2002-07-10 14:24 ` Jean-Pierre Rosen
2002-07-10 19:17 ` Ted Dennison
2002-07-10 17:18 ` Jeffrey D. Cherry
1 sibling, 1 reply; 7+ messages in thread
From: Jean-Pierre Rosen @ 2002-07-10 14:24 UTC (permalink / raw)
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 773 bytes --]
"David Rasmussen" <pinkfloydhomer@yahoo.com> a �crit dans le message news:
> So with corresponds roughly to an #include of some header file that
> defines prototypes etc. for some other compilation unit in C++, and use
> corresponds roughly to "using namespace Whatever", assuming that the
> things included were in a seperate namespace?
Roughly :-)
> "with" and only appear at the top of a unit. Where can "use" appear?
>
At any place a declaration can appear, and like any declaration, its effects extends from where it is declared to the corresponding
"end". In addition, it can also appear in a context clause.
--
---------------------------------------------------------
J-P. Rosen (rosen@adalog.fr)
Visit Adalog's web site at http://www.adalog.fr
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: with and use
2002-07-10 13:45 ` David Rasmussen
2002-07-10 14:24 ` Jean-Pierre Rosen
@ 2002-07-10 17:18 ` Jeffrey D. Cherry
1 sibling, 0 replies; 7+ messages in thread
From: Jeffrey D. Cherry @ 2002-07-10 17:18 UTC (permalink / raw)
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 2649 bytes --]
David Rasmussen <pinkfloydhomer@yahoo.com> wrote in news:3D2C3A69.8070207
@yahoo.com:
> Jean-Pierre Rosen wrote:
> > "David Rasmussen" <pinkfloydhomer@yahoo.com> a �crit dans le message
> > news: 3D2C2FF9.4020300@yahoo.com...
> >
<snip>
> >> Secondly, where is with and use typically used, and what is the
> >> difference between them?
> >>
> >
> > A with clause means that a compilation unit needs the services from
> > another *compilation unit* (i.e. a package, subprogram or generic
> > which is separately compiled).
> >
> > A use clause factors out a *package*, i.e. you don't have to repeat
> > the package name in front of every element. Since a package can (but
> > needs not) be a compilation unit, there are cases where both clauses
> > can be applied, but they are really orthogonals.
> >
>
> So with corresponds roughly to an #include of some header file that
> defines prototypes etc. for some other compilation unit in C++, and use
> corresponds roughly to "using namespace Whatever", assuming that the
> things included were in a seperate namespace?
>
> "with" and only appear at the top of a unit. Where can "use" appear?
>
> /David
>
You are quite correct here to associate the Ada "use" clause with the C++
"using namespace" using-directive. You are also reasonably correct regarding
the "with" clause, but I would qualify the C++ equivalent a bit further. I
would say the Ada "with" clause more closely corresponds to a #include of
some header file that defines a namespace containing function prototypes
and/or other declarations.
The Ada "with" clause should appear in what would be the C++ global scope if
C++ were limited to a single class, namespace, or function per translation
unit. The Ada "use" clause can appear in what would be the C++ global scope
or in the C++ block scope.
One final note would be that the Ada "use" clause is only valid for packages.
It cannot be used for a "with"ed subpgrogram or generic unit. If the generic
unit is a package, the "use" clause can be issued after the instantiation.
For example:
with Some_Generic_Package;
procedure Main is
package Instance is new Some_Generic_Package( ... );
use Instance;
begin -- Main
null;
end Main;
This shows the "with" clause pulling a generic package (a C++ template unit)
into the Main procedure's context, instantiating the package in the
declarative region, and then making the contents of the new package directly
visible via a "use" clause (in a C++ block scope).
Hope that helps!
--
Regards,
Jeffrey D. Cherry
Senior IV&V Analyst
Northrop Grumman Information Technology
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: with and use
@ 2002-07-10 17:20 Gautier direct_replies_not_read
0 siblings, 0 replies; 7+ messages in thread
From: Gautier direct_replies_not_read @ 2002-07-10 17:20 UTC (permalink / raw)
> > "with" and only appear at the top of a unit. Where can "use" appear?
>At any place a declaration can appear, and like any declaration, its
>effects extends from where it is declared to the corresponding
>"end". In addition, it can also appear in a context clause.
Maybe these examples could help to understand the "why".
(1)
with GL, GLU, GLUT, GLOBE_3D, Game_control, Level_Manager;
procedure GloDemo1 is
...
-- Here I don't want to open visibility
...
procedure Display is
use GL, GLOBE_3D; -- <-- Here but just here I want to open
-- visibility of the full GL bindings
begin
-- No need of "GL."
Clear( COLOR_BUFFER_BIT or DEPTH_BUFFER_BIT );
PushMatrix;
Translate ( -eye(0), -eye(1), -eye(2) );
Rotate( rot(0), 1.0, 0.0, 0.0 );
Rotate( rot(1), 0.0, 1.0, 0.0 );
Rotate( rot(2), 0.0, 0.0, 1.0 );
...
PopMatrix;
GL.Flush;
GLUT.SwapBuffers;
end Display;
...
(2)
with Ada.Text_IO; use Ada.Text_IO;
procedure xxx(f:File_Type) is
begin
null;
end xxx;
(3)
with Ada.Text_IO;
procedure xxx(f:Ada.Text_IO.File_Type) is
begin
null;
end xxx;
____________________________________________________________
Gautier -- http://www.mysunrise.ch/users/gdm/index.htm#Ada
NB: For a direct answer, address on the Web site!
_________________________________________________________________
Join the world�s largest e-mail service with MSN Hotmail.
http://www.hotmail.com
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: with and use
2002-07-10 14:24 ` Jean-Pierre Rosen
@ 2002-07-10 19:17 ` Ted Dennison
0 siblings, 0 replies; 7+ messages in thread
From: Ted Dennison @ 2002-07-10 19:17 UTC (permalink / raw)
"Jean-Pierre Rosen" <rosen@adalog.fr> wrote in message news:<aghg1g$r9b$1@s1.read.news.oleane.net>...
> "David Rasmussen" <pinkfloydhomer@yahoo.com> a �crit dans le message news:
> > So with corresponds roughly to an #include of some header file that
> > defines prototypes etc. for some other compilation unit in C++, and use
> > corresponds roughly to "using namespace Whatever", assuming that the
> > things included were in a seperate namespace?
> Roughly :-)
Yeah, in the same way that a hacksaw roughly corresponds to a
chainsaw: You generally use them for the same kinds of tasks, but
thinking of them as the *exact* same thing can be hazardous to your
health.
> > "with" and only appear at the top of a unit. Where can "use" appear?
> >
> At any place a declaration can appear, and like any declaration, its effects
> extends from where it is declared to the corresponding
> "end". In addition, it can also appear in a context clause.
The use clause is very contraversial, as it effectivly flattens a
namespace that was (possibly) designed to be hierarchal. I generally
suggest that beginners avoid the "use" clause (although not "use
type"). Practice a while using full dot notation until you are
competent enough with Ada to intelligently decide where you stand on
the issue.
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2002-07-10 19:17 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-07-10 13:00 with and use David Rasmussen
2002-07-10 13:25 ` Jean-Pierre Rosen
2002-07-10 13:45 ` David Rasmussen
2002-07-10 14:24 ` Jean-Pierre Rosen
2002-07-10 19:17 ` Ted Dennison
2002-07-10 17:18 ` Jeffrey D. Cherry
-- strict thread matches above, loose matches on Subject: below --
2002-07-10 17:20 Gautier direct_replies_not_read
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox