jeremyhansen / rooksguide-cplusplus

The Rook's Guide to C++
44 stars 12 forks source link

Char signed assumption #21

Open LeviSchuck opened 10 years ago

LeviSchuck commented 10 years ago

A reviewer commented this, and I know this to be true.

"In table 9.1 of chapter 9 "Data types and Conversion" you wrote that the char data type ranges from -128 to 127, but that's not true, because the standard doesn't say that a char is signed or unsigned, it depends on the implementation. A char can be an unsigned char and in that case it will range from 0 to 255."

jeremyhansen commented 10 years ago

A later commented added the following:

A char also isn't guaranteed to be 8 bits. POSIX requires it, but in ISO C++, a char can be as large as a long long int (http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2012/n3337.pdf, section 3.9.1, paragraph 2)