|
Boost : |
Subject: Re: [boost] [outcome] some problems compiling
From: Glen Fernandes (glen.fernandes_at_[hidden])
Date: 2017-05-24 12:02:23
On Wed, May 24, 2017 at 7:28 AM, Niall Douglas wrote:
>>>> 2. This class and subsequent functions are defined in anonymous
>>> namespace.
>>>> This means they are redefined and recompiled in each translation unit,
>>> and
>>>> remain a per TU definition. Is that intent?
>>>
>>> Yes. Because it's a C source file, you would get symbol collision errors
>>> otherwise.
>>>
>>
>> Can't the same effect be achieved with declaring the functions inline? And
>> then you would only get one symbol.
>
> We would then collide with anyone who later includes <windows.h>,
> because we are defining the exact same symbol names as windows in order
> to avoid including windows, so it would be an ODR violation.
>
> It's a trick to include windows without including windows which only
> works on MSVC by taking advantage of its lax parser. That's why on clang
> we just go ahead and include windows.
Boost libraries already avoid including <windows.h> by leveraging
Boost.WinAPI which provides the definitions necessary (and are added
to as needed).
Your use of an unnamed namespace for the types is questionable.
Depending on the compiler, I think you should want to decorate them
with __attribute__ ((__may_alias__)).
Glen
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk