I'm a little confused and I'm trying to understand structure padding and how variables are actually laid out in memory on a 32-bit machine ARM. This is a generic question just to help me understand basic.
Suppose I have this program:
Let's assume RAM addresses look something like this:
variable a occupies 1 byte, while struct test s occupies 8 bytes in total: 1 byte for s.x, 3 bytes of padding, and 4 bytes for s.y. What I'm trying to understand is how the compiler places these variables in RAM. Where would a be located, and where would s.x and s.y typically be placed in memory?
I know the exact layout is implementation-defined. I'm just trying to understand the general idea of how compilers lay out local variables and structure variable in memory and how alignment affects that process.
Suppose I have this program:
C:
#include <stdio.h>
struct test {
char x;
int y;
};
int main()
{
struct test s;
char a = 'z';
s.x = 'b';
s.y = 10;
return 0;
}
Code:
0x00
0x01
0x02
0x03
0x04
0x05
0x06
0x07
0x08
...
I know the exact layout is implementation-defined. I'm just trying to understand the general idea of how compilers lay out local variables and structure variable in memory and how alignment affects that process.