No, you should have multiplied by CHAR_BITS. Check out this thread: unsigned char
Seek and ye shall find. quaere et invenies.
"Simplicity does not precede complexity, but follows it." -- Alan Perlis
"Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
"The only real mistake is the one from which we learn nothing." -- John Powell
Other boards: DaniWeb, TPS
Unofficial Wiki FAQ: cpwiki.sf.net
My website: http://dwks.theprogrammingsite.com/
Projects: codeform, xuni, atlantis, nort, etc.
sizeof returns the number of bytes and there are always 8bits to a byte.
If you've read the suggested thread you'd knew that not always
To be or not to be == true
I did read the thread and didn't see anything about non 8 bit bytes.
Read it again.Originally Posted by dnysveen
1) sizeof doesn't return the number of bytes, it returns the multiples of char's size.
2) Even if it did, nowhere in the C++ standard does it say that a byte is 8 bits large. Nor does it anywhere in computer theory. This is a usage based solely on the fact that it is so common.
3) Neither is the size of char guaranteed anywhere; there's only a minimum specified.
All the buzzt!
"There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
- Flon's Law
hmm... but the C++ Standard (section 5.3.3) states that:1) sizeof doesn't return the number of bytes, it returns the multiples of char's size.
The sizeof operator yields the number of bytes in the object representation of its operand.
In the same paragraph, it also states:
sizeof(char), sizeof(signed char) and sizeof(unsigned char) are 1; the result of sizeof applied to any other fundamental type (3.9.1) is implementation-defined.
I believe this means that a char is exactly one byte in C++, though of course how large is a char or a byte in terms of bits is only given as a minimum.