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=-1.1 required=5.0 tests=BAYES_00, PP_MIME_FAKE_ASCII_TEXT autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII X-Google-Thread: 103376,c999596f866f316a X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2002-07-10 10:19:54 PST Path: archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-01!sn-post-01!supernews.com!corp.supernews.com!not-for-mail From: "Jeffrey D. Cherry" Newsgroups: comp.lang.ada Subject: Re: with and use Date: Wed, 10 Jul 2002 17:18:46 -0000 Organization: Northrop Grumman Message-ID: References: <3D2C2FF9.4020300@yahoo.com> <3D2C3A69.8070207@yahoo.com> User-Agent: Xnews/4.11.09 X-Complaints-To: newsabuse@supernews.com Xref: archiver1.google.com comp.lang.ada:26990 Date: 2002-07-10T17:18:46+00:00 List-Id: David Rasmussen wrote in news:3D2C3A69.8070207 @yahoo.com: > Jean-Pierre Rosen wrote: > > "David Rasmussen" a �crit dans le message > > news: 3D2C2FF9.4020300@yahoo.com... > > > >> 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