A typical 32-bit (8-byte) processor cannot be accessed as large as two or four bytes.
Given the following structure
struct {
char a[3];
short int b;
long int c;
char d[3];
};
You may think that memory is held as shown below (12 bytes):
+-------+-------+-------+-------+
| | a | b |
+-------+-------+-------+-------+
| | b | c |
+-------+-------+-------+-------+
| | c | d |
+-------+-------+-------+-------+
The processor is easier to approach (12 bytes):
+-------+-------+-------+
| | a |
+-------+-------+-------+
| | b |
+-------+-------+-------+-------+
| | c |
+-------+-------+-------+-------+
| | d |
+-------+-------+-------+
This isn't a good way for the processor either. Because a,b,d isn't full of eight bytes So most compilers fill in the remaining parts. This is called a pad. The results of pad appear as follows.
+-------+-------+-------+-------+
| | a | pad1 |
+-------+-------+-------+-------+
| | b | pad2 |
+-------+-------+-------+-------+
| | c |
+-------+-------+-------+-------+
| | d | pad3 |
+-------+-------+-------+-------+
© 2024 OneMinuteCode. All rights reserved.