0

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.

rlbond
  • 65,341
  • 56
  • 178
  • 228
f0b0s
  • 2,978
  • 26
  • 30
  • posting version number of boost might be helpful. It may be found in macro BOOST_LIB_VERSION defined in boost/version.hpp – P Shved Aug 27 '09 at 22:36
  • sorry, i've posted my compiler but forgotten boost. i've got the latest (1.40.0) version. – f0b0s Aug 27 '09 at 22:37
  • what kind of code? i do #include "boost/thread/shared_mutex.hpp" and get a warning somewhere inside microsec_time_clock.hpp. date_type d(curr_ptr->tm_year + 1900, curr_ptr->tm_mon + 1, curr_ptr->tm_mday); ^ here. – f0b0s Aug 27 '09 at 23:27
  • It goes away when you don't include `shared_mutex`? – GManNickG Aug 27 '09 at 23:35
  • yes, because shared mutex is the only one boost lib that i use. – f0b0s Aug 27 '09 at 23:38
  • i tried boost 1.39 -- same problem. – f0b0s Aug 27 '09 at 23:39

2 Answers2

2

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
  • 22,897
  • 2
  • 80
  • 94
  • 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 Aug 29 '09 at 10:31
  • 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 Aug 29 '09 at 21:53
0

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
  • 299,747
  • 42
  • 398
  • 622