I'm dealing with some code at work that includes an expression of the form
-(sizeof(struct foo))
i.e. the negation of a size_t
, and I'm unclear on what the C and C++ standards require of compilers when they see this. Specifically, from looking around here and elsewhere, sizeof
returns an unsigned integral value of type size_t
. I can't find any clear reference for specified behavior when negating an unsigned integer. Is there any, and if so, what is it?
Edit: Ok, so there are some good answers regarding arithmetic on unsigned types, but it's not clear that this is in fact such. When this negates, is it operating on an unsigned integer, or converting to a signed type and doing something with that? Is the behavior to expect from the standards "imagine it's the negative number of similar magnitude and then apply the 'overflow' rules for unsigned values"?