Boost logo

Boost :

From: Robert Ramey (ramey_at_[hidden])
Date: 2007-11-02 17:56:36


Its worse than that. It conflicts with the array optimization changes and
results in creating archives which can't be read.

Robert Rmey

David Abrahams wrote:
> on Fri Nov 02 2007, "Boris Gubenko" <Boris.Gubenko-AT-hp.com> wrote:
>
>> Two serialization library tests: test_demo_portable_archive[_dll]
>> fail
>> to compile on many platforms with invalid type conversion error. I
>> did
>> not check all the platforms, but I'd expect it to fail on any big
>> endian platform.
>
> I can't imagine how your change would fix an endianness problem.
> Also, your change relies on the nonportable (implementation-defined)
> behavior of reinterpret_cast.
>
> I think the correct change to silence the type conversion error is
>
> char * first = static_cast<char *>(static_cast<void
> *>(const_cast<long*>(& l)));
>
> However the code in itself invokes undefined behavior by modifying a
> constant object (l). The byte reversal needs to be done in a separate
> buffer.
>
>> The patch below fixes the problem, verified on HP-UX with
>> both aC++ and gcc.
>>
>> Ok to commit?
>>
>> Index: example/portable_binary_oarchive.hpp
>> ===================================================================
>> --- example/portable_binary_oarchive.hpp (revision 40687)
>> +++ example/portable_binary_oarchive.hpp (working copy)
>> @@ -76,7 +76,7 @@
>>
>> // we choose to use litle endian
>> #ifdef BOOST_BIG_ENDIAN
>> - char * first = static_cast<char *>(static_cast<void
>> *>(& l)); + char * first = reinterpret_cast<char
>> *>(const_cast<long *>(& l)); char * last = first +
>> sizeof(l) - 1; for(;first < last;++first, --last){
>> char x = *last;
>>
>> Thanks,
>> Boris
>>
>> _______________________________________________
>> Unsubscribe & other changes:
>> http://lists.boost.org/mailman/listinfo.cgi/boost


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