Topic: namespace foo {#include <a_std_lib.h>}
Author: Giacomo Catenazzi <cate@math.ethz.ch>
Date: Wed, 6 Jun 2001 16:19:29 GMT Raw View
Hello.
I have a problem:
I use on a library the construct:
namespace foo {
#include <a_std_lib.h>
}
(where a_std_lib.h is any std library (e.g. complex.h))
But this cause problem on some compilers (e.g. the prerelease og gcc-3.0).
I sent a bug to gcc, and they think that this construct is not
legal:
> > is permitted in userland by [17.4.1.1]/2, "All library
> > entities ... are defined within the namespace std or
> > namespaces nested within namespace std." Here we're
> > nesting namespace std inside another namespace.
>
> good point.
>
> > If this code is valid, then I think this becomes another
> > "funky C wrapping header problem" PR.
>
> I think you are right, and that this code is not allowed.
What do you think about this?
I don't undertand why the std doesn't allow this case.
IMHO it can simplify the transition between new library versions
or also solve conflicts between library.
[ The original problem:
I work on a huge numerical library. It use 'real' as floating point
type (typedef double real). Now I should implement some
complex-number functions, but the complex header include the function
'double real(complex<double>)'. Thus name conflict, but the library is
too huge to replace real to float_t.
And I don't find other simple methods (without to edit 200/500 files).
(How to include all C++ library without the 'using namespace std'?)
]
giacomo
---
[ 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://www.research.att.com/~austern/csc/faq.html ]
Author: remove.haberg@matematik.su.se (Hans Aberg)
Date: Wed, 6 Jun 2001 20:19:41 GMT Raw View
In article <3B1E49E4.186E5260@math.ethz.ch>, cate@dplanet.ch wrote:
>I use on a library the construct:
>
>namespace foo {
>#include <a_std_lib.h>
>}
>(where a_std_lib.h is any std library (e.g. complex.h))
Whatever, it is a strango thing: If you include <complex.h>, then you
first get names like std::real, plus a "using std::real", which should
define a global name "::real", and both are then put within the namespace
foo, so you should have the names foo::std::real and foo::real.
That is, this is how the names are _declared_; you still only have one
name defined, std::real, so when you use foo::std::real, the linker will
not find that name (unless it is a template or something that causes the
definition to occur).
It is simpler to use
#include <complex>
in which case you only have one name, std::real, and no global ::real.
> The original problem:
>I work on a huge numerical library. It use 'real' as floating point
>type (typedef double real). Now I should implement some
>complex-number functions, but the complex header include the function
>'double real(complex<double>)'. Thus name conflict, but the library is
>too huge to replace real to float_t.
>And I don't find other simple methods (without to edit 200/500 files).
>(How to include all C++ library without the 'using namespace std'?)
Now the answer ends up in the wrong newsgroup: I think this should have
been a comp.lang.c++.moderated question.
But if you put your numerical library in say a namespace "num", then
#include <complex>
namespace num {
typedef double real;
}
will produce the names std::real and num::real which do not conflict.
Otherwise, it is not very hard to change a name like "real" to some more
appropriate like "floating" in hundreds of files if using an appropriate
editor: Make a backup of the original sources, and then set up the editor
to search for "real" and replace by "floating". I regularly do this in a
project of close to 200 files, and I usually inspect each occurance before
making the replacement.
Hans Aberg * Anti-spam: remove "remove." from email address.
* Email: Hans Aberg <remove.haberg@member.ams.org>
* Home Page: <http://www.matematik.su.se/~haberg/>
* AMS member listing: <http://www.ams.org/cml/>
---
[ 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://www.research.att.com/~austern/csc/faq.html ]