开发者

byte aligned to odd address. Does it violate access boundary theory?

开发者 https://www.devze.com 2023-02-22 06:15 出处:网络
stru开发者_如何学Cct X { char a; char b; int c; }; In the above struct, member b is stored in an odd address. I checked this on a linux/x86 enviroment
stru开发者_如何学Cct X {
char a;
char b;
int c;
};

In the above struct, member b is stored in an odd address. I checked this on a linux/x86 enviroment

Many web pages talks about inability of processors to access odd addresses. If it was true, then there should been padding of 1 byte between member a and b, such that b is stored in an even address.

What am I missing?


Acessing a char at an odd address is always okay. However, an int at an odd address could cause a problem. However, the compiler will automatically add padding to between struct fields if needed. I'm assuming C/C++ as your language.

0

精彩评论

暂无评论...
验证码 换一张
取 消