KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
I'm working on a 32-bit machine, so I suppose that the memory alignment should be 4 bytes. Say I have this struct: typedef struct { unsigned short v1; unsigned short v2; unsigned short v3; } myStruct; The plain added size is 6 bytes, and I suppose that the aligned size should be 8, but sizeof(myStruct) returns me 6. However if I write: typedef struct { unsigned short v1; unsigned short v2; unsigned short v3; int i; } myStruct; the plain added size is 10 bytes, aligned size shall be 12, and this time sizeof(myStruct) == 12 . Can somebody explain what is the difference?
Tags (comma-separated)
Save Edits
Cancel