Steven T. Hatton wrote:
> i386 (32-bit version), i486, P, PII, PIII, P4...
> #include <iostream>
> int main() {
> char c('c');
> std::cout<<c<<std::endl;
> }
>
> Assume char is 8-bits. The smallest retrievable unit of storage is a
> 32-bit word. That means the CPU puts c in a 32-bit word. What will
> occupy the other 24 bits of the word?
This statement is not correct. The 32-bit property, regarding i386
architectures, means that 32 bit units _can_ be accessed (because the
physical bus interface has 32 bits width). However, i386 _adresses_
8-bit units and stores them byte-by-byte. You can easily store four
bytes into a 32 bit integer variable.
If you want to proof this, try the following:
1 #include <stdio.h>
2 #include <string.h>
3 int main(){
4 char array1[16], array2[16];
5 int array3[4];
6 strcpy(array1, "a test string\n");
7 memcpy(array3, array1, sizeof(array3));
8 memcpy(array2, array3, sizeof(array2));
9 printf("%s", array2);
10 return 0;
11}
12
Line 6, the source char-array is initialized.
Line 7: an anonymous copy to an intermediate int-array is made
Line 8: an anonymous copy to the destination char-array is made
The fact that this program outputs 'a test string' proofs that int units
are stored to (at least) four times char units. Since it is known that
int occupies 32 bits, a char unit can not occupy more than eight bits.
(qed)
Note that on a real 32-bit architecture, like e.g. TMS320C3x DSP from
Texas Instruments, this little program would not work, since a char is
stored into 32 bit units (padding the upper 24 bits with zero, to answer
your question above).
Note also, that on 64 bit intel processors, an int can hold eight char
units.
HTH,
cheers,
Axel
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]