Boost logo

Boost :

Subject: Re: [boost] [pool] detail/mutex.hpp may include windows.h and pollute namespace with windows definitions.
From: Marsh Ray (marsh_at_[hidden])
Date: 2010-10-09 11:14:47


On 10/09/2010 06:19 AM, Joshua Boyce wrote:
>
> So, a definition which does not required the Windows headers would be as
> follows:
>
> #pragma pack(push, 8)
>
>> typedef struct _RTL_CRITICAL_SECTION
>
> {
>
> void* DebugInfo;
>
> long LockCount;
>
> long RecursionCount;
>
> void* OwningThread;
>
> void* LockSemaphore;
>
> void* SpinCount;
>
> } RTL_CRITICAL_SECTION, *PRTL_CRITICAL_SECTION;
>
>> #pragma pack(pop)

Suggestion:

namespace boost { namespace boost_windows_h {

#pragma pack(push, 8)
        struct RTL_CRITICAL_SECTION
        {
                void * reserved1;
                long reserved2;
                long reserved3;
                void * reserved4;
                void * reserved5;
                void * reserved6;
        };

        typedef RTL_CRITICAL_SECTION * PRTL_CRITICAL_SECTION;
#pragma pack(pop)

} }

The 'typedef struct' thing is a holdover from C.

No reason to keep that struct tag, I don't think intended for use.
Leading underscores are reserved for compiler vendors (like Microsoft)
and organizations that ship non-standard headers (like Microsoft).

The field data seems to change with OS versions, so code is not supposed
to rely on it. The fields are effectively reserved.

Personally, I'd use a lowercase struct name (it's not a macro after all)
and omit the silly typedef. I'd be less concerned with it looking like
the official headers if the point is to not include them. Just re-use
the minimum needed for compatibility, which in this case is just
sizeof() and __alignof().

- Marsh


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk