In code that is supposed to be quite portable, in a many person, many environment project, I have to deal with a problem with code that negates unsigned int
(and same problem in other places negating std::size_t
).
The intent is to create the additive inverse of that value (modulo MAX_VAL+1 where MAX_VAL is the max value of the type) and I found other questions on this topic confirm that is the standard specified behavior.
VS2012, (with compile time options I cannot easily learn) calls that line an error. The developer, with access to that environment, changed -U
to -1*U
, which compiles in that environment. I have a low opinion of that change and I'm not happy with the work I would need to go through to portability test that change to code that was correct in the first place.
I expect there is some #pragma, which will tell VS2012 to allow -U
to have its standards defined meaning. I expect that will be easier to find than exploring any consequences of -1*U
(beyond the fact that I think -1*U
is disgusting).
But I'm hoping to get some language lawyer and/or VS2012 guru opinions before trying any of that.
Edit, I should have linked the relevant previous answer: What should happen to the negation of a size_t (i.e. `-sizeof(struct foo)`))?
I believe the original code is correct based on that answer. I want to know how to make VS2012 believe the code is correct.
The error message, is:
error C4146: unary minus operator applied to unsigned type, result still unsigned