|
Boost Users : |
From: Edward Diener (eddielee_at_[hidden])
Date: 2003-03-05 18:18:25
Douglas Gregor wrote:
> On Tuesday 04 March 2003 10:16 pm, Edward Diener wrote:
>> Beman Dawes wrote:
>>> Have you considered proposing a macro which will automatically apply
>>> the appropriate #pragma for the compiler? That way the knowledge of
>>> what #pragma to apply for each compiler only has to be maintained
>>> and tested in one place.
>>
>> Excellent idea. Now why didn't I think of that <g>. It's the old
>> forest and the trees thing, no doubt.
>>
>> The macro would have to be in the form of:
>>
>> BOOST_DATA_LAYOUT_BEGIN
>>
>> at the beginning of a header file surrounding any
>> class/struct/union/enum declarations and
>>
>> BOOST_DATA_LAYOUT_END
>>
>> at the end.
>
> Would you willing to provide the definitions for these macros (or, as
> I suspect, begin/end headers)? I'd be happy to use them, but as I've
> never needed such a thing I don't know the particular pragmas to use.
I can give anyone the #pragmas for VC++ and BCB and their meanings for data
layout. You, or any other Boost developer, should be able to take it from
there. John Maddock also knows them well since there are in the Regex++
header files. For other compilers, if they exist, others would have to
supply them.
----------------------------------------------------------------------------
----------------------------------------------------
For BCB the begin and end #pragmas would be of the form:
#pragma option push -option [ -option ... ]
#pragma option pop
where option for data layout would be:
-an = packing, where n = 1,2,4,8,16 with the default being 8
-b(-) = enum size, where -b = integer size ( default ) and -b- = byte-sized
when possible
-Ve(-) = zero-length empty base classes where -Ve = turns it on and -Ve- =
turns it off ( default )
-Vx(-) = zero-length class data members where -Vx = turns it on and -Vx- =
turns it off ( default )
A setting for a header which sets the defaults would be
#pragma option push -a8 -b -Ve- -Vx-
// Class/struct/union/enums
#pragma option pop
----------------------------------------------------------------------------
----------------------------------------------------
For VC++ the begin and end #pragmas just encompass the packing alignment
since VC++ doesn't allow any other data layout alternatives as BCB does
above. The form is
#pragma pack(push,n)
#pragma pack(pop)
where n is your 1,2,4,8,16 packing with 8 being the default.
A setting for a header which sets the default would be
#pragma pack(push,8)
// Class/struct/unions
#pragma pack(pop)
----------------------------------------------------------------------------
-----------------------------------------------------
Two important things to realize when using these in header files
1) Don't have any intervening #includes in between the pushing and popping
of options
2) You can do multiple and nested push and pops so there is much flexibility
with this system, but of course KISS still applies very well here.
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net