Sam Black Sam Black - 3 months ago 24
C++ Question

error C4146: unary minus operator applied to unsigned type, result still unsigned

I try to build CRF++ in Visual Studio 2013 and get this error in the last line:

array_[begin + siblings[i].code].base =
value_ ?
static_cast<array_type_>(-value_[siblings[i].left]-1) :
static_cast<array_type_>(-siblings[i].left-1);



error C4146: unary minus operator applied to unsigned type, result
still unsigned


Specifically, it is in darts.h, line 189.

I built again in Visual Studio 2015 then there is no error.

How can I fix this in Visual Studio 2013?

Answer

Try this:

int tmp = static_cast<int>(siblings[i].left);

array_[begin + siblings[i].code].base =
            value_ ?
            static_cast<array_type_>(-value_[siblings[i].left]-1) :
            static_cast<array_type_>(-tmp - 1);