Serialization - 'size_t' to 'std::streamsize' error
Ok....this is really confusing.
I successfully created a small test project several months ago using the
Boost Serialization library to serialize some binary data. I am now
attempting to add binary serialization to a production project, and I
receive a bunch of compiler warnings.
I can still compile and execute the test application with no warnings or
errors.
I am using VS2005 with boost 1.34.1
I have included the first few compiler warnings below...
1>C:\Program
Files\boost\boost_1_34_1\boost/archive/basic_binary_oprimitive.hpp(136) :
warning C4267: 'argument' : conversion from 'size_t' to 'std::streamsize',
possible loss of data
1> C:\Program
Files\boost\boost_1_34_1\boost/archive/basic_binary_oprimitive.hpp(120) :
while compiling class template member function 'void
boost::archive::basic_binary_oprimitive
I'm surprised this didn't seem to get answered. I wouldn't worry about the warning in your case. Here's the difference: size_t is unsigned, streamsize is signed. This means that if they're both the same datawidth - which is likely - you'll get the warning below because the range of size_t tops out at a *much* higher value than that of streamsize. If you're really concerned about this you may be able to use boost numerics to validate that the value of size_t is actually within the range of streamsize. To merely quell the warning, an explicit cast should do the trick. mike On Wed, 2007-10-31 at 11:57 -0500, Dave Nay wrote:
Ok....this is really confusing.
I successfully created a small test project several months ago using the Boost Serialization library to serialize some binary data. I am now attempting to add binary serialization to a production project, and I receive a bunch of compiler warnings.
I can still compile and execute the test application with no warnings or errors.
I am using VS2005 with boost 1.34.1
I have included the first few compiler warnings below...
1>C:\Program Files\boost\boost_1_34_1\boost/archive/basic_binary_oprimitive.hpp(136) : warning C4267: 'argument' : conversion from 'size_t' to 'std::streamsize', possible loss of data 1> C:\Program Files\boost\boost_1_34_1\boost/archive/basic_binary_oprimitive.hpp(120) : while compiling class template member function 'void boost::archive::basic_binary_oprimitive
::save_binary(const void *,size_t)' 1> with 1> [ 1> Archive=boost::archive::binary_oarchive, 1> Elem=char, 1> Tr=std::char_traits<char> 1> ] 1> C:\Program Files\boost\boost_1_34_1\boost/archive/detail/oserializer.hpp(91) : see reference to function template instantiation 'void boost::archive::basic_binary_oprimitive ::save<T>(const T &)' being compiled 1> with 1> [ 1> Archive=boost::archive::binary_oarchive, 1> Elem=char, 1> Tr=std::char_traits<char>, 1> T=unsigned char 1> ] 1> C:\Program Files\boost\boost_1_34_1\boost/archive/detail/oserializer.hpp(244) : see reference to function template instantiation 'void boost::archive::save_access::save_primitive (Archive &,const T &)' being compiled 1> with 1> [ 1> Archive=boost::archive::binary_oarchive, 1> T=unsigned char 1> ] Thanks, Dave
-- Dave Nay CIVision, LLC
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
Thanks Mike, I understood the reason for the error (signed vs. unsigned). I was (am) just confused as to why this error is showing up within the Boost serialization code (not my code, Boost code). I have added explicit casts to the locations in the basic_binary_oprimitive.hpp and basic_binary_iprimitive.hpp header files, and this of course supresses the errors, but it doesn't really satisfy my confusion. Dave -----Original Message----- From: boost-users-bounces@lists.boost.org [mailto:boost-users-bounces@lists.boost.org] On Behalf Of Michael Linck Sent: Friday, November 09, 2007 5:41 PM To: boost-users@lists.boost.org Subject: Re: [Boost-users] Serialization - 'size_t' to'std::streamsize' error I'm surprised this didn't seem to get answered. I wouldn't worry about the warning in your case. Here's the difference: size_t is unsigned, streamsize is signed. This means that if they're both the same datawidth - which is likely - you'll get the warning below because the range of size_t tops out at a *much* higher value than that of streamsize. If you're really concerned about this you may be able to use boost numerics to validate that the value of size_t is actually within the range of streamsize. To merely quell the warning, an explicit cast should do the trick. mike On Wed, 2007-10-31 at 11:57 -0500, Dave Nay wrote:
Ok....this is really confusing.
I successfully created a small test project several months ago using the Boost Serialization library to serialize some binary data. I am now attempting to add binary serialization to a production project, and I receive a bunch of compiler warnings.
I can still compile and execute the test application with no warnings or errors.
I am using VS2005 with boost 1.34.1
I have included the first few compiler warnings below...
1>C:\Program Files\boost\boost_1_34_1\boost/archive/basic_binary_oprimitive.hpp(136) : warning C4267: 'argument' : conversion from 'size_t' to 'std::streamsize', possible loss of data 1> C:\Program Files\boost\boost_1_34_1\boost/archive/basic_binary_oprimitive.hpp(120) : while compiling class template member function 'void boost::archive::basic_binary_oprimitive
::save_binary( const void *,size_t)' 1> with 1> [ 1> Archive=boost::archive::binary_oarchive, 1> Elem=char, 1> Tr=std::char_traits<char> 1> ] 1> C:\Program Files\boost\boost_1_34_1\boost/archive/detail/oserializer.hpp(91) : see reference to function template instantiation 'void boost::archive::basic_binary_oprimitive ::save<T>(cons t T &)' being compiled 1> with 1> [ 1> Archive=boost::archive::binary_oarchive, 1> Elem=char, 1> Tr=std::char_traits<char>, 1> T=unsigned char 1> ] 1> C:\Program Files\boost\boost_1_34_1\boost/archive/detail/oserializer.hpp(244) : see reference to function template instantiation 'void boost::archive::save_access::save_primitive (Archive &,const T &)' being compiled 1> with 1> [ 1> Archive=boost::archive::binary_oarchive, 1> T=unsigned char 1> ] Thanks, Dave
-- Dave Nay CIVision, LLC
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
participants (2)
-
Dave Nay
-
Michael Linck