From: "Jeffrey D. Cherry" <yrrehcdj@hcetu.ten>
Subject: Re: with and use
Date: Wed, 10 Jul 2002 17:18:46 -0000
Date: 2002-07-10T17:18:46+00:00 [thread overview]
Message-ID: <Xns92476910DD84jdcherryutechnet@216.168.3.40> (raw)
In-Reply-To: 3D2C3A69.8070207@yahoo.com
[-- 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
next prev parent reply other threads:[~2002-07-10 17:18 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
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 [this message]
-- strict thread matches above, loose matches on Subject: below --
2002-07-10 17:20 Gautier direct_replies_not_read
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox