在 7/8/21 8:05 PM, johnsfine--- via Gcc-help 写道:
This is not the forum for such a discussion. But I want to make people reading this aware that many expert C and C++ programmers (likely a majority) consider that advice to avoid unsigned types to be horrible advice. I advise people to avoid signed types and I do so myself. If an integer value won't be negative, it shouldn't be signed. That makes your intent clearer to anyone reading your code, and (especially in x86-64) lets the compiler generate smaller and faster code.
That makes no sense. Would you prefer unsigned integers to signed ones, for something that can only be one of {1,2,3,4}? Just because something can't be negative, does not mean it should be unsigned.
Conversion between `uint64_t` and `double` is much slower than `int64_t` on some platforms, e.g. x86, so 'smaller and faster code' is also groundless [1].
A signed integer is a value that denotes the number or amount of something, such as bytes, characters, files, seconds, kilometers, or even dollars. An unsigned integer is merely a fixed-sized collection of bits. That's the only fundamental difference.
[1] https://gcc.godbolt.org/z/6YY61rhGe -- Best regards, LIU Hao
Attachment:
OpenPGP_signature
Description: OpenPGP digital signature