unary minus operator applied to unsigned type, result still unsigned
-
This warning from post title is more an information than a warning: u
nary minus operator applied to unsigned type, result still unsigned
but is signaled here:static unsigned char buffer[512];
static long long var = -sizeof(buffer) - 1; // <-- warning C4146: unary minus operator applied to unsigned type, result still unsignedStill, how can I rid of this warning ?
-
This warning from post title is more an information than a warning: u
nary minus operator applied to unsigned type, result still unsigned
but is signaled here:static unsigned char buffer[512];
static long long var = -sizeof(buffer) - 1; // <-- warning C4146: unary minus operator applied to unsigned type, result still unsignedStill, how can I rid of this warning ?
You can cast the result of the
sizeof
call to along long
prior to apply it the unary minus operator:static long long var = -((long long)sizeof(buffer)) - 1;
It makes sense when you think of what should the result be when you try to negate a value of a type which does not accept negative values.
"Five fruits and vegetables a day? What a joke! Personally, after the third watermelon, I'm full."
-
You can cast the result of the
sizeof
call to along long
prior to apply it the unary minus operator:static long long var = -((long long)sizeof(buffer)) - 1;
It makes sense when you think of what should the result be when you try to negate a value of a type which does not accept negative values.
"Five fruits and vegetables a day? What a joke! Personally, after the third watermelon, I'm full."