views:

267

answers:

2

Hi. I'm new in using boost and have a problem. I need shared_mutex function in my project. So I've done

#include "boost/thread/shared_mutex.hpp"

And compiled my project. My MSVC 2005 with "treat warnings as errors" stops compilation because of a warning:

c:\\...\microsec_time_clock.hpp(103) : warning C4244: 'argument' : conversion from 'int' to 'unsigned short', possible loss of data

I have no idea, why shared_mutex needs microseconds function (I've read than boost libraries have rather big dependences list), but i can't compile my project. I've googled a bit, found same problem, but no decision.

UPDATE: I'm compiling boost now, but i want to put all sources to my open-source project, including boost.thread.shared_mutex.

+1  A: 

Various Boost libraries generate all kinds of warnings on Visual Studio builds at level 4. We just disable them.

For example, one of our precompiled header files has:

#pragma warning(push, 0)
#include <boost/asio.hpp>
#include <boost/asio/streambuf.hpp>
#include <boost/lexical_cast.hpp>
#include <boost/noncopyable.hpp>
#include <boost/thread.hpp>
#include <boost/scoped_ptr.hpp>
#include <boost/shared_ptr.hpp>
#include <boost/system/error_code.hpp>
#include <boost/xpressive/xpressive.hpp>
#pragma warning(pop)
Tim Sylvester
i`m student, not a professional, but i don`t understand how can boost programmers write code that warns, and we (programmers, who use boost) can ignore theese warnings.
f0b0s
I don't know if this is covered by the Boost docs anywhere, but the zlib FAQ has a good response: -- I get this ... warning ... Can't you guys write proper code? -- Many years ago, we gave up attempting to avoid warnings on every compiler in the universe. It just got to be a waste of time, and some compilers were downright silly. So now, we simply make sure that the code always works. -- http://www.zlib.net/zlib_faq.html#faq35
Tim Sylvester
A: 

I'll bet they're doing a += on an unsigned short. The result of the addition gets cast to an int implicitly, then needs to be downcast back to an unsigned short for the assignment.

Mark Ransom