No, you should have multiplied by CHAR_BITS. Check out this thread: http://cboard.cprogramming.com/showthread.php?t=86809
No, you should have multiplied by CHAR_BITS. Check out this thread: http://cboard.cprogramming.com/showthread.php?t=86809
dwk
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
All problems in computer science can be solved by another level of indirection,
except for the problem of too many layers of indirection.
– David J. Wheeler
I did read the thread and didn't see anything about non 8 bit bytes.
Read it again.Originally Posted by dnysveen
Kurt
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!
CornedBee
"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.
Last edited by laserlight; 12-23-2006 at 10:43 PM.
Look up a C++ Reference and learn How To Ask Questions The Smart WayOriginally Posted by Bjarne Stroustrup (2000-10-14)