Re: Anonymous-namespace references vs extern references
* Angel Tsankov:
Which of the following definitions of tcerr is preferrable and why?
1)
// header file
namespace {
::std::wostream& tcerr = ::std::wcerr;
}
Don't use anonymous namespaces in header files. There's only one global level
anonymous namespace in each compilation unit. The above sneaks in an identifier
in the anonymous namespace of the each implementation file that uses this
header, and in that anon namespace there might well be something called tcerr.
Also it's a good idea to not use "T" functionality at all, and a really bad idea
to use it (more to write, more possible bugs, less portable and non-standard).
So the above is wrongheaded on 2 different counts.
2)
// header file
extern ::std::wostream& tcerr;
// source file
::std::wostream& tcerr = ::std::wcerr;
This one would be slightly less unpreferable than the first.
But do you really want your Unicode messages to be translated to some single
byte charset that you don't control (most probably Windows ANSI Western)?
I'd think not.
It's just silly.
For internal diagnostic messages and logging, go for English only, a well known
single byte charset, and deal with e.g. Unicode filenames (if you must)
explicitly, instead of relying on some unspecified lossy translation.
Cheers, & hth.,
- Alf
--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?