Default struct fields alignment
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2024-06-25 5:48 AM
'param3' is a uint16_t field, so I expected a 2 bytes address alignment and not a 4 bytes one.
- Labels:
-
STM32G0 Series
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2024-06-25 5:52 AM - edited ‎2024-06-25 5:57 AM
Why, so the processor doesn't fault.
The CM0(+) being particularly fussy.
Other CMx will fault on misaligned LDRD/STRD.
For compact structures for files perhaps __packed or similar, but then you must address misalignment issues yourself.
Situations where you array the data, or make composite structures.
Up vote any posts that you find helpful, it shows what's working..
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2024-06-25 5:57 AM
Thank you @Tesla DeLorean, for the very quick response.
So you are saying that all fields inside a struct, by default, are 4 bytes aligned, despite of their type.
Isn't it?
Thank you,
Carlo
