Topic: Namepaces


Author: maxtal@physics.su.OZ.AU (John Max Skaller)
Date: Mon, 21 Feb 1994 21:47:12 GMT
Raw View
In article   Ulf writes:
>
>The Resolution-paper r.3.3.1.1 says:
>>...
>>using-declaration:
>> using Namespacename::Identifier;
>>using-directive:
>> using namespace Namespacename;
>>...
>
>1) May the Identifier in the using-declaration be a namespace?

 Yes.
>
>2) Why do I have to write 'using namespace X;' and not just 'using X;'?

 Because of (1). The two are distinct. It was felt that
since the semantics of using declarations and directives are
quite distinct,  visibly distinct syntax should be used,
and, compiler enforcement and error checking enabled.

 You may NOT say:

 using namespace namespacename::Ident

if Ident is not a namespace. There's no way to check that if
the keyword "namespace" is not there to distinguish the two
forms. Distinction on the basis of type of the Ident is
a poor idea: no redundancy.

>3) r.3.3.1.3 says:
>>... Unnamed namespaces make global static (r.7.1.1) redundant....
>
>Does this mean that function and variable names that are members of
>an unnamed namespace will not appear in the objectfile and thus
>not be accessable from outside this compilation-unit (like it is
>the case with global static fcts/vars)?

 Yes.
>
>4) This is rather an implementation-question than a language-question,
>but it would help understanding how namespaces work:
>a) Will the namespaces of identifiers be encoded into their names in
>the objectifile, so that the linker can ditinginguish between A::var1
>and B::var1?

 Yes.

>b) But if so, how can I wrap a namespace around a library/object-file
>(that was compiled without namespaces) afterwads? E.g.:

 You cant without an object file conversion tool.

>5) In some articles #include <header> was mentioned. As far as I
>understood it
>#include <header.h> works like it always worked, and
>#include <header> wraps the declarations that are
>in the file 'header.h' into a namespace called 'header'.
>- Please corect me if I'm not right.

 You are right. But backwards. ALL the symbols are in namespace,
the .h file simply #includes the non.h file and then
does a using declaration for each name.

--
        JOHN (MAX) SKALLER,         INTERNET:maxtal@suphys.physics.su.oz.au
 Maxtal Pty Ltd,      CSERVE:10236.1703
        6 MacKay St ASHFIELD,     Mem: SA IT/9/22,SC22/WG21
        NSW 2131, AUSTRALIA