Topic: namespace translation units


Author: Maribeth Romeo <mromeo@Adobe.COM>
Date: 1999/09/16
Raw View
--------------316391EE0502A438C627D253
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit

Does anybody know if a single namespace can span C++ source files or
does the definition of a namespace need to be in a single translation
unit.  I found this info from MS, but not sure of it's accuracy.  I know
that the code will compile if you place namespaces in separate
translation units, but I'm getting mucho link errors.  Thanks for any
info.
Maribeth


     Unlike other declarative regions, the definition of a
     namespace can be split over several parts of a single
     translation unit.
     namespace A {
         // declare namespace A variables
         int i;
         int j;
     }

     namespace B {
         ...
     }
         .
         .
         .
     namespace A {
         // declare namespace A functions
         void func(void);
         int int_func(int i);
     }
     When a namespace is continued in this manner, after its
     initial definition, the continuation is called an
     extension-namespace-definition.

--------------316391EE0502A438C627D253
Content-Type: text/html; charset=us-ascii
Content-Transfer-Encoding: 7bit

<!doctype html public "-//w3c//dtd html 4.0 transitional//en">
<html>
Does anybody know if a single namespace can span C++ source files or does
the definition of a namespace need to be in a single translation unit.&nbsp;
I found this info from MS, but not sure of it's accuracy.&nbsp; I know
that the code will compile if you place namespaces in separate translation
units, but I'm getting mucho link errors.&nbsp; Thanks for any info.
<br>Maribeth
<br>&nbsp;
<blockquote><b>Unlike other declarative regions, the definition of a namespace
can be split over several parts of a single translation unit.</b>
<br><b>namespace A {</b>
<br><b>&nbsp;&nbsp;&nbsp; // declare namespace A variables</b>
<br><b>&nbsp;&nbsp;&nbsp; int i;</b>
<br><b>&nbsp;&nbsp;&nbsp; int j;</b>
<br><b>}</b><b></b>
<p><b>namespace B {</b>
<br><b>&nbsp;&nbsp;&nbsp; ...</b>
<br><b>}</b>
<br><b>&nbsp;&nbsp;&nbsp; .</b>
<br><b>&nbsp;&nbsp;&nbsp; .</b>
<br><b>&nbsp;&nbsp;&nbsp; .</b>
<br><b>namespace A {</b>
<br><b>&nbsp;&nbsp;&nbsp; // declare namespace A functions</b>
<br><b>&nbsp;&nbsp;&nbsp; void func(void);</b>
<br><b>&nbsp;&nbsp;&nbsp; int int_func(int i);</b>
<br><b>}</b>
<br><b>When a namespace is continued in this manner, after its initial
definition, the continuation is called an extension-namespace-definition.</b></blockquote>
</html>

--------------316391EE0502A438C627D253--
---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html              ]





Author: "Phlip" <see@web.page>
Date: 1999/09/16
Raw View
Maribeth Romeo wrote:

>>Does anybody know if a single namespace can span C++ source files or does
the definition of a namespace need to be in a single translation unit.  I
found this info from MS, but not sure of it's accuracy.  I know that the
code will compile if you place namespaces in separate translation units, but
I'm getting mucho link errors.  Thanks for any info.

Please don't post in HTML - it exposes bugs in my newsreader.

A single namespace can span anything you want. For example, 'namespace std'
contains all of the C library (except macros and other typeless muck), and
all of STL. But if in one file you included <string>, and in another you
used <iostream>, and in another you used both, then the compiler would just
pull in all of the namespace parts it needs in each trans unit. It would not
fret "where's the rest?"

Put another way, a namespace has no in-memory representation (like a class
does), so it has nothing the compiler must complete.

--
 Phlip at politizen dot com                  (address munged)
======= http://users.deltanet.com/~tegan/home.html =======




[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html              ]






Author: Francis Glassborow <francis@robinton.demon.co.uk>
Date: 1999/09/16
Raw View
In article <37E0F08A.33CD343D@adobe.com>, Maribeth Romeo
<mromeo@Adobe.COM> writes
><html>
>Does anybody know if a single namespace can span C++ source files or does
>the definition of a namespace need to be in a single translation unit

Namespaces can be re-opened and so can be extended in other translation
units.

Francis Glassborow      Journal Editor, Association of C & C++ Users
64 Southfield Rd
Oxford OX4 1PA          +44(0)1865 246490
All opinions are mine and do not represent those of any organisation


[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html              ]