Кажется, я не могу найти соответствующие части в стандарте C, полностью определяющие поведение унарного минусового оператора с беззнаковыми операндами.
Стандарт C ++ 2003 года (да, C ++, терпите меня занесколько строк) в 5.3.1c7 сказано: The negative of an unsigned quantity is computed by subtracting its value from 2^n, where n is the number of bits in the promoted operand.
Однако в стандарте C 1999 года такого явного утверждения не содержится и не дается четкого определения унарного поведения ни в 6.5.3.3c1,3.ни в 6.5c4.В последнем написано Some operators (the unary operator ~, and the binary operators <<, >>, &, ^, and |, ...) ... return values that depend on the internal representations of integers, and have implementation-defined and undefined aspects for signed types.)
, что исключает унарный минус, и вещи кажутся неопределенными.
Этот более ранний вопрос относится к книге K & R ANSI C, раздел A.7.4.5что говорит The negative of an unsigned quantity is computed by subtracting the promoted value from the largest value of the promoted type and adding one
.
Каким будет стандарт С 1999 года, эквивалентный приведенной выше цитате из книги?
6.2.5c9 говорит: A computation involving unsigned operands can never overflow, because a result that cannot be represented by the resulting unsigned integer type is reduced modulo the number that is one greater than the largest value that can be represented by the resulting type.
ЭтоЭто?Или что-то еще мне не хватает?