|
This thread is locked; no one can reply to it. |
1
2
|
unsigned char or u8? |
Evert
Member #794
November 2000
|
Quote: Wrong, the types integer types have guaranteed minimum types. Look it up.
Yes, they do. A "char" is size 1 by definition, a short is at least as large as a char, an int is at least as large as a short and should correspond to the machine's native word size and a long is at least the size of an int. |
Elias
Member #358
May 2000
|
Yes, that's how I read it, they could all be 8-bit (of course, in practice, as many compilers will do that as use 9-bit char ). But what it means is, if you need a minimum number of bits, it's best to use something like int_least32_t. Usually you don't and then int is fine. [Edit:] We are talking about C++ here btw, not C99 which is different (and which that home.att.net site linked above seems to talk about). -- |
torhu
Member #2,727
September 2002
|
Just for fun, here's a quote from "The C++ Programming Language, special edition", ยง4.6 for you: Quote: In addition, is is guaranteed that a char has at least 8 bits, a short at least 16 bits, and a long at least 32 bits. It might not be the standard, but Stroustroup tends to get his facts right. He also probably has a copy of the standard on his shelf, which I don't. The minimum 16 bit shorts ands ints, and 32 bit longs, are mentioned in K&R 1989 edition. I didn't bother trying to find a note about char sizes. EDIT: Of course, if you're programming an 8-bit cpu, the C compiler might not follow the standard in regards to minimum sizes. I wouldn't be surprized if C compilers that use 8 bit ints exist. And maybe there's no floating point support at all, etc. |
Elias
Member #358
May 2000
|
Well, if that book was published before 1998, the author definitely did not have a copy of the standard -- |
torhu
Member #2,727
September 2002
|
Good point, edition I've got is from 1997. Although he was actually on the committe, and probably had a bunch of drafts laying about. Besides, I have the 2002 printing. |
Elias
Member #358
May 2000
|
Well, I figured out the problem - the C++ standard (neither the one from 1998, nor the updated one from 2003, nor the upcoming C++v0) does not specify any minimum sizes within the text of the standard. But, all the above three reference the C90 standard (C++v0 may or may not reference C99 instead from what I understand) and so they inherit minimum sizes from there. So what you said is right - int is at least 16 bit and long at least 32 bit. However you cannot look that up in the C++ standard, only in the C standard referenced by it -- |
|
1
2
|