LINUX.ORG.RU

История изменений

Исправление fsb4000, (текущая версия) :

C23: https://open-std.org/JTC1/SC22/WG14/www/docs/n3096.pdf

6.3.1.3 Signed and unsigned integers

1)  When a value with integer type is converted to another integer type other than bool, if the value
can be represented by the new type, it is unchanged.

2) Otherwise, if the new type is unsigned, the value is converted by repeatedly adding or subtracting
one more than the maximum value that can be represented in the new type until the value is in the
range of the new type.

3) Otherwise, the new type is signed and the value cannot be represented in it; either the result is
implementation-defined or an implementation-defined signal is raised.

Смотрим пункт 2.

Пусть у нас есть int a = -1. -1 не входит в unsigned int [0, 2^32]

Значит добавляем UINT_MAX.

-1 + 4 294 967 296 = 4 294 967 295.

4 294 967 295 входит в диапазон, который представим типом unsigned int. Заканчиваем добавление/отнимание.

Это и есть твои 0xFF…F

То есть да. Стандартом С23 это гарантируется.

Исходная версия fsb4000, :

C23: https://open-std.org/JTC1/SC22/WG14/www/docs/n3096.pdf

6.3.1.3 Signed and unsigned integers

1)  When a value with integer type is converted to another integer type other than bool, if the value
can be represented by the new type, it is unchanged.

2) Otherwise, if the new type is unsigned, the value is converted by repeatedly adding or subtracting
one more than the maximum value that can be represented in the new type until the value is in the
range of the new type.

3) Otherwise, the new type is signed and the value cannot be represented in it; either the result is
implementation-defined or an implementation-defined signal is raised.

Смотрим пункт 2.

Пусть у нас есть int a = -1. -1 не входит в unsigned int [0, 2^32]

Значит добавляем UINT_MAX.

-1 + 4 294 967 296 = 4 294 967 295.

4 294 967 295 входит в диапазон, который представим типом unsigned int. Заканчиваем добавление/отнимание.

Это и есть твои 0xFF…F

То есть да. Стандартом С23 это гарантируется.

То есть