On 2017/5/3 23:12, David Grayson wrote:
> When you say "optimal", what are you optimizing for?
>
For decreasing object file sizes and link time, apparently.

> The UsbView code uses that header file in several different translation
> units, so you end up having a bunch of duplicate GUID definitions for all
> the GUIDs defined in winioctl.h, like GUID_DEVINTERFACE_DISK.  To prevent
> multiple definition errors, the Microsoft header files using the selectany
> attribute.
Similar solutions are used for C++ template specializations (functions 
or classes) and `inline` functions (note that C++ `inline` is different 
from C `inline` be it C99 or GNU89).

> I don't know why Microsoft engineered such a complicated solution for
> defining GUIDs, but they did, and I would think we should try to make our
> header files compatible with it.  If it just takes a few preprocessor if
> statements that check the GCC version, that seems OK.
I have no idea either, but the case here is abnormal: If the macro 
`INITGUID` is *not* defined before `#include`ing _guiddef.h_, those 
GUIDs/UUIDs are declared (instead of defined) only as `extern const` 
objects. Our behavior is hence consistent with Microsoft's own headers 
(I only have VS2017 at hand and I have examined it).

If your conclusion
 > If __declspec(selectany) is not used on the prototype but later used 
on a definition, GCC seems to ignore it, and you can get 
multiple-definition errors at link time.
is true, then you should first try adding `-DINITGUID` in your 
`CPPFLAGS`, effectively forcing defining every GUID in your project. If 
it does solve the problem, you can check the pre-processed source files 
produced by _both MSVC and GCC_ (without that `-E` option) to see where 
the macro `INITGUID` is defined.

If it turns out that a non-selectany declaration followed by a selectany 
definition is causing linker errors, it is probably a GCC bug and not a 
MinGW-w64 bug and we are unable to fix it after all.

-- 
Best regards,
LH_Mouse


------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Mingw-w64-public mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/mingw-w64-public

Reply via email to