quote: Original post by MadKeithV
Bjarne Stroustrup, the C++ Programming Language:
Sizes of C++ objects are expressed in terms of multiples of the size of a char, so by definition the size of a char is 1. The size of an object or type can be obtained using the sizeof operator. This is what is guaranteed about sizes of fundamental types:
1 == sizeof( char ) <= sizeof( short ) <= sizeof( int ) <= sizeof( long )
In addition, it is guaranteed that a char has at least 8 bits.
Note the "at least" in there. There is no guarantee for the 8 bits, it could be 16, depending on the system size of a char.
That is all well and good, but Mr. Stroustrup is not the final word on C++. The ISO/ANSI board is the final word. And quoting their documents (per my earlier post) (anyone know where the final or most current version of the standards doc is on the web) it says bytes. Would you like to argue that a byte on some systems is not 8 bits.
Also, given Mr Stroustrup's definition, wouldn't the calculation of an array size given by many in this thread still work out correctly in all instances? Can you have a type smaller than a char on a system where char is 16 bits. I don't think sizeof is going to return .5 for such a type. So can it exist?
And while we are on the subject, and I may be wrong here, even though sizeof is an operator, I believe its result is always calculated at compile time and not at run time. Anyone know if I'm right or wrong on that one.
Mike Roberts
aka milo
mlbobs@telocity.com
Edited by - milo on October 4, 2000 5:21:34 PM
Edited by - milo on October 4, 2000 5:24:44 PM