Boost logo

Boost Users :

Subject: Re: [Boost-users] Serialization: C4308 warning with MSVC9
From: Robert Ramey (ramey_at_[hidden])
Date: 2010-05-19 02:31:19


Political Confusion wrote:
> --- On Tue, 5/18/10, Robert Ramey <ramey_at_[hidden]> wrote:
>
>> From: Robert Ramey <ramey_at_[hidden]>
>> Subject: Re: [Boost-users] Serialization: C4308 warning with MSVC9
>> To: boost-users_at_[hidden]
>> Date: Tuesday, May 18, 2010, 11:57 PM
>> Political Confusion wrote:
>>> --- On Tue, 5/18/10, Robert Ramey <ramey_at_[hidden]>
>> wrote:
>>>
>>>> From: Robert Ramey <ramey_at_[hidden]>
>>>> Subject: Re: [Boost-users] Serialization: C4308
>> warning with MSVC9
>>>> To: boost-users_at_[hidden]
>>>> Date: Tuesday, May 18, 2010, 10:35 PM
>>>> Political Confusion wrote:
>>>>> Political Confusion <politicalconfusion <at> yahoo.com> writes:
>>>>>
>>>>>>
>>>>>> I'm using Boost 1.43 with MSVC9 SP1 and Windows SDK v7 on
>>>>>> Windows 7. I've
>>>>> created a class like the "A Very
>>>>>> Simple Case" example (i.e. added 'access' as friend and a
>>>>>> templated serialize function). In serialize, I just
>>>> archive 10 ints (signed
>>>>>> and unsigned). It compiles fine, but when
>> I add program code to
>>>>>> save my class to a text_oarchive, I get a
>> warning:
>>>>>>
>>>>>>
>>>>
>> c:\third-party\boost_1_43_0\boost\mpl\print.hpp(51) :
>>>> warning C4308:
>>>>>> negative integral constant converted to unsigned type
>>>>>>
>>>>>> Line 51 of print.hpp is: enum { n = sizeof(T) + -1 };
>>>>>>
>>>>>> Calling sizeof() on my class gives a 44. I do not get any warning
>>>>>> when I load
>>>>> my class with text_iarchive. And
>>>>>> both save and load appear to work fine.
>>>>>>
>>>>>
>>>>> I had to add the following to make this warning go away:
>>>>>
>>>>> BOOST_CLASS_TRACKING( my_class,
>>>> boost::serialization::track_never )
>>>>
>>>> This warning should precede a long call chain. If
>> you
>>>> go to the the
>>>> call BEFORE this, you should find a comment which
>> indicates
>>>> why this
>>>> warning is invoked.
>>>>
>>>> Robert Ramey
>>>>
>>>>
>>>>
>>>> _______________________________________________
>>>> Boost-users mailing list
>>>> Boost-users_at_[hidden]
>>>> http://lists.boost.org/mailman/listinfo.cgi/boost-users
>>>>
>>>
>>> Hello Robert,
>>>
>>> That's what I did. The lines above the warning
>>> (boost/archive/detail/check.hpp(98)):
>>>
>>> // saving an non-const object
>> of a type not marked "track_never)
>>>
>>> // may be an indicator of an
>> error usage of the
>>> // serialization library and
>> should be double checked.
>>> // See documentation on object
>> tracking. Also, see the
>>> // "rationale" section of the
>> documenation
>>> // for motivation for this
>> checking.
>>>
>>>
>> BOOST_STATIC_WARNING(typex::value);
>>>
>>> So I added the BOOST_CLASS_TRACKING() line. I
>> get the same warning
>>> if I modify save_schedule() in demo.cpp to instantiate
>> a gps_position
>>> and save it to oa. gps_position was the example
>> I used for my class.
>>>
>>> Thanks for the reply and thanks for your work.
>>
>> But this begs the real question. Do you want tracking
>> or don't you.
>>
>> Without tracking -
>> you won't be able to serialize
>> apointer.
>> and you'll missing the opptimization of space
>> if the same object is
>> serialized more than once.
>> It will be faster to save and restore
>> With tracking
>> The opposite will be true
>>
>> So the decision to use tracking shouldn't made as to
>> the easiest way to fix
>> the warning.
>> The other way is to make the object we're saving
>> non-const.
>>
>> Robert Ramey
>>
>>
>>
>>
>> _______________________________________________
>> Boost-users mailing list
>> Boost-users_at_[hidden]
>> http://lists.boost.org/mailman/listinfo.cgi/boost-users
>>
>
> I don't think I need tracking, but I can't say for sure. This is my
> class:
>
> class WindowPlacement : public WINDOWPLACEMENT
> {
> public:
>
> WindowPlacement() { length = sizeof( WINDOWPLACEMENT ); }
>
> private:
>
> friend class se::access;
>
> template < typename Archive >
> void serialize( Archive& ar, const unsigned int version )
> {
> ar & flags;
> ar & showCmd;
> ar & ptMinPosition.x;
> ar & ptMinPosition.y;
> ar & ptMaxPosition.x;
> ar & ptMaxPosition.y;
> ar & rcNormalPosition.left;
> ar & rcNormalPosition.top;
> ar & rcNormalPosition.right;
> ar & rcNormalPosition.bottom;
> }
> };
>
> I load it to an object declared on the stack when my main window is
> created. I save it from a stack object before my main window is
> destroyed. In case you don't know, WINDOWPLACEMENT is a struct
> defined by Microsoft:
>
> typedef struct tagWINDOWPLACEMENT { /* wndpl */
> UINT length;
> UINT flags;
> UINT showCmd;
> POINT ptMinPosition;
> POINT ptMaxPosition;
> RECT rcNormalPosition;
> } WINDOWPLACEMENT;
>

In this case, I would guess that turning off tracking would make sense.
This is because you never save via a pointer and you do it to/from the
stack.

> I don't understand "The other way is to make the object we're saving
> non-const." My instantiated class has to be non-const in order to
> pass it to GetWindowPlacement/SetWindowPlacement of the Windows API.

Look at the rationale section of the documentation for a full explanation.

Robert Ramey

>
> Thanks for your time,
>
> Michael
>
>
> =


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