Topic: namespace aliases and extension namespace definition


Author: Martin von Loewis <loewis@informatik.hu-berlin.de>
Date: 1999/02/15
Raw View
sbnaran@localhost.localdomain.COM (Siemel Naran) writes:

> What's the reason to disallow this?

Ambiguities, I guess:

namespace A{
  namespace B{
    namespace C{}
  }
  namespace Alias = B::C;

  namespace B{
    namespace Alias{
      void func();
    }
  }
}

What would you expect this to do: Open a new namespace A::B::Alias, or
reopen A::B::C? My feeling is that people would likely to be confused,
no matter how you interpret this.

Regards,
Martin
---
[ 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: Christopher Eltschka <celtschk@physik.tu-muenchen.de>
Date: 1999/02/15
Raw View
Martin von Loewis wrote:
>
> sbnaran@localhost.localdomain.COM (Siemel Naran) writes:
>
> > What's the reason to disallow this?
>
> Ambiguities, I guess:
>
> namespace A{
>   namespace B{
>     namespace C{}
>   }
>   namespace Alias = B::C;
>
>   namespace B{
>     namespace Alias{
>       void func();
>     }
>   }
> }
>
> What would you expect this to do: Open a new namespace A::B::Alias, or
> reopen A::B::C? My feeling is that people would likely to be confused,
> no matter how you interpret this.

There are also problems with multiple files:

// header.h

namespace A
{
  void foo();
}

namespace B=A;

// file1.cc

#include "header.h" // could be indirect!

namespace B // would extend A
{
  void bar();
}

// file2.cc

// no #include "header.h"

namespace B // opens new namespace (alias is file-scope!)
{
  void baz();
}

Confused? ;-)


[ 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: sbnaran@fermi.ceg.uiuc.edu (Siemel Naran)
Date: 1999/02/16
Raw View
On 15 Feb 1999 17:13:44 GMT, Christopher Eltschka
>Martin von Loewis wrote:

>> namespace A{
>>   namespace B{
>>     namespace C{}
>>   }
>>   namespace Alias = B::C;
>>
>>   namespace B{
>>     namespace Alias{
>>       void func();
>>     }
>>   }
>> }
>>
>> What would you expect this to do: Open a new namespace A::B::Alias, or
>> reopen A::B::C? My feeling is that people would likely to be confused,
>> no matter how you interpret this.

What g++ does is open a new namespace A::B::Alias.
Here was my test driver,
   int main() { A::B::C::func(); } // error
   int main() { A::B::Alias::func(); } // ok


>There are also problems with multiple files:
>
>// header.h
>
>namespace A
>{
>  void foo();
>}
>
>namespace B=A;
>
>// file1.cc
>
>#include "header.h" // could be indirect!
>
>namespace B // would extend A
>{
>  void bar();
>}
>
>// file2.cc
>
>// no #include "header.h"
>
>namespace B // opens new namespace (alias is file-scope!)
>{
>  void baz();
>}
>
>Confused? ;-)

Is this what you're saying?  The program "file2.cc" has different
meaning depending on whether "header.h" has been included or not.
This dependency of meaning is bad because it severly limits the use
of pre-compiled headers.

--
----------------------------------
Siemel B. Naran (sbnaran@uiuc.edu)
----------------------------------
---
[ 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: Martin von Loewis <loewis@informatik.hu-berlin.de>
Date: 1999/02/16
Raw View
sbnaran@fermi.ceg.uiuc.edu (Siemel Naran) writes:

> What g++ does is open a new namespace A::B::Alias.

I'm not surprised; I wrote it that way :-)

[namespace definition depending on whether alias was seen]
> Is this what you're saying?  The program "file2.cc" has different
> meaning depending on whether "header.h" has been included or not.
> This dependency of meaning is bad because it severly limits the use
> of pre-compiled headers.

No, this example was made under the assumption that aliases can be
used for re-opening; which is not the case in Standard C++. Therefore,
file2.cc is just ill-formed if header.h was included (redefinition of
identifier B). This is no problems for pre-compiled headers.

Regards,
Martin
---
[ 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              ]