Почему в C++ предпочтение отдается подписанному, а не неподписанному?C++

Программы на C++. Форум разработчиков
Ответить
Гость
 Почему в C++ предпочтение отдается подписанному, а не неподписанному?

Сообщение Гость »


I'd like to understand better why choose over

Код: Выделить всё

unsigned
?

Personally, I've never liked signed values unless there is a valid reason for them. e.g. count of items in an array, or length of a string, or size of memory block, etc., so often these things cannot possibly be negative. Such a value has no possible meaning. Why prefer when it is misleading in all such cases?

I ask this because both Bjarne Stroustrup and Chandler Carruth gave the advice to prefer over

Код: Выделить всё

unsigned
here (approx 12:30').

I can see the argument for using over or - is the "most natural" data width for the target machine architecture.

But signed over unsigned has always annoyed me. Are signed values genuinely faster on typical modern CPU architectures? What makes them better?


Источник: https://stackoverflow.com/questions/187 ... igned-in-c
Ответить

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

Вернуться в «C++»