[m-rev.] for review: fix float field structure padding/packing problems
Julien Fischer
juliensf at csse.unimelb.edu.au
Tue Dec 6 13:39:03 AEDT 2011
On Tue, 6 Dec 2011, Peter Wang wrote:
> On 2011-12-06, Julien Fischer <juliensf at csse.unimelb.edu.au> wrote:
>>>
>>> You didn't really think it would be that easy, did you? ;-)
>>>
>>> s/_declspec/__declspec/
>>>
>>> and apparently the argument of the align attribute must be an integer
>>> constant, so we can't use an expression such as sizeof(MR_Word).
>>> (This is with MSVC 2008, I haven't yet tried a later version.)
>>>
>>> I think the appropriate thing to do here is add MR_BYTES_PER_WORD back
>>> to the runtime and use that in the above. (I say add back, because the
>>> only place it appears is in mercury_conf_bootstrap.h.)
>>>
>>> In the meantime I've just hardcoded a value in there - I'll let you know
>>> how that went once my workspace finishes building.
>>
>> By itself the above does not work with MSVC. We also need to pass the -Zp4
>> as a flag to cl, then the test case works.
>
> Thanks. It looks like __declspec(align) didn't do what I thought
> and is actually unnecessary here.
>
> Instead of passing -Zp4 we can write:
>
> #ifdef MR_MSVC
> #pragma pack(push, MR_BYTES_PER_WORD)
> #endif
> struct s { ... };
> #ifdef MR_MSVC
> #pragma pack(pop)
> #endif
>
> Or hidden behind macros:
>
> #define MR_PUSH_PRAGMA_PACK __pragma(pack(push, MR_BYTES_PER_WORD))
> #define MR_POP_PRAGMA_PACK __pragma(pack(pop))
>
> I'm reading that __pragma was only introduced in VS2008/VC9 so it may be
> too recent for us to use.
No, I think requring VS2008 or later is fine.
Julien.
--------------------------------------------------------------------------
mercury-reviews mailing list
Post messages to: mercury-reviews at csse.unimelb.edu.au
Administrative Queries: owner-mercury-reviews at csse.unimelb.edu.au
Subscriptions: mercury-reviews-request at csse.unimelb.edu.au
--------------------------------------------------------------------------
More information about the reviews
mailing list