
On Tue, Nov 27, 2012 at 5:41 PM, Marshall Clow <mclow.lists@gmail.com> wrote:
On Nov 27, 2012, at 9:55 AM, Felipe Magno de Almeida <felipe.m.almeida@gmail.com> wrote:
Hello,
AFAIK, unnamed namespaces are dangerous in headers. There is a commentary just above the function definition:
// this needs to be in an un-named namespace because it is not a template // and might get included in several compilation units. This could cause // multiple definition errors at link time.
But it seems the better thing would be to define it inline. It is exactly because it can be used in several translation units that it can cause an ODR violation if defined in a unnamed namespace AFAIK.
I have no problem with declaring it inline, but that's just a suggestion. The compiler is completely free to generate code for it out-of-line.
I didn't meant I want the function to be inlined by the compiler. What I mean is that putting it in a unnamed namespace causes undefined behavior(AFAIK). So, the solution to being used by multiple translation units should be to declare it inline, and not use an unnamed namespace.
-- Marshall
Marshall Clow Idio Software <mailto:mclow.lists@gmail.com>
A.D. 1517: Martin Luther nails his 95 Theses to the church door and is promptly moderated down to (-1, Flamebait). -- Yu Suzuki
Regards, -- Felipe Magno de Almeida