Groups | Search | Server Info | Login | Register
Groups > comp.arch.embedded > #32468
| From | Grant Edwards <invalid@invalid.invalid> |
|---|---|
| Newsgroups | comp.arch.embedded |
| Subject | Re: arm-gcc, Cortex-M0+, uint64_t and alignment |
| Date | 2026-01-20 17:48 +0000 |
| Organization | PANIX Public Access Internet and UNIX, NYC |
| Message-ID | <10kof5q$929$1@reader2.panix.com> (permalink) |
| References | <10kns7l$1733k$1@dont-email.me> <10ko98i$1bptj$1@dont-email.me> <10kob7m$qel$1@reader2.panix.com> <10kocr4$1d65l$1@dont-email.me> |
On 2026-01-20, pozz <pozzugno@gmail.com> wrote: > Il 20/01/2026 17:41, Grant Edwards ha scritto: >> On 2026-01-20, David Brown <david.brown@hesbynett.no> wrote: >> >>> You can't reduce the alignment of a struct or its elements by adding an >>> __aligned_ attribute to the struct itself or any of its fields. The >>> best you can do on the struct itself is __attribute__((packed)). But >>> that can come with disadvantages, and inefficient use. >> >> Yep making a structure aligned is an excellent way to introduce subtle >> bugs that happen when somebody, somewhere passes a pointer to one of >> those structure fields to some library function. Aargh, my bad. I meant that making a strucutre _packed_ is an excellent way to introduce subtle bugs that happen when somebody, somewhere passes a pointer to one of those structure fields to some library function. > However, as long as the application runs on Cortex-M0+, the aligned > version shouldn't introduce issues, should it? A non-packed structure should always be OK. A packed structure will work fine as long as it's being accessed by code that "knows" it's packed. You can pass a pointer to packed struct to a function as long as it's declared in that function as a pointer to a packed struct: the compiler will generate extra code to deal with accesses to values that are misaligned due to the packing. However, passing a pointer to an packed field structure (e.g. to a uint64_t) to a function where it was declared as a normal "uint64_t *p" can cause failures on ARM targets. It will work OK on X86. I think it used to work OK on m68k also. IIRC SPARC failed in similar ways to ARM. -- Grant
Back to comp.arch.embedded | Previous | Next — Previous in thread | Next in thread | Find similar
arm-gcc, Cortex-M0+, uint64_t and alignment pozz <pozzugno@gmail.com> - 2026-01-20 13:26 +0100
Re: arm-gcc, Cortex-M0+, uint64_t and alignment David Brown <david.brown@hesbynett.no> - 2026-01-20 17:07 +0100
Re: arm-gcc, Cortex-M0+, uint64_t and alignment Grant Edwards <invalid@invalid.invalid> - 2026-01-20 16:41 +0000
Re: arm-gcc, Cortex-M0+, uint64_t and alignment pozz <pozzugno@gmail.com> - 2026-01-20 18:09 +0100
Re: arm-gcc, Cortex-M0+, uint64_t and alignment David Brown <david.brown@hesbynett.no> - 2026-01-20 18:44 +0100
Re: arm-gcc, Cortex-M0+, uint64_t and alignment pozz <pozzugno@gmail.com> - 2026-01-21 09:11 +0100
Re: arm-gcc, Cortex-M0+, uint64_t and alignment David Brown <david.brown@hesbynett.no> - 2026-01-21 10:02 +0100
Re: arm-gcc, Cortex-M0+, uint64_t and alignment pozz <pozzugno@gmail.com> - 2026-01-21 15:58 +0100
Re: arm-gcc, Cortex-M0+, uint64_t and alignment David Brown <david.brown@hesbynett.no> - 2026-01-21 17:13 +0100
Re: arm-gcc, Cortex-M0+, uint64_t and alignment pozz <pozzugno@gmail.com> - 2026-01-21 17:57 +0100
Re: arm-gcc, Cortex-M0+, uint64_t and alignment David Brown <david.brown@hesbynett.no> - 2026-01-22 10:03 +0100
Re: arm-gcc, Cortex-M0+, uint64_t and alignment Grant Edwards <invalid@invalid.invalid> - 2026-01-20 17:48 +0000
Re: arm-gcc, Cortex-M0+, uint64_t and alignment David Brown <david.brown@hesbynett.no> - 2026-01-20 18:41 +0100
Re: arm-gcc, Cortex-M0+, uint64_t and alignment Grant Edwards <invalid@invalid.invalid> - 2026-01-20 18:10 +0000
Re: arm-gcc, Cortex-M0+, uint64_t and alignment David Brown <david.brown@hesbynett.no> - 2026-01-20 22:32 +0100
Re: arm-gcc, Cortex-M0+, uint64_t and alignment Grant Edwards <invalid@invalid.invalid> - 2026-01-21 03:38 +0000
Re: arm-gcc, Cortex-M0+, uint64_t and alignment David Brown <david.brown@hesbynett.no> - 2026-01-21 08:54 +0100
Re: arm-gcc, Cortex-M0+, uint64_t and alignment pozz <pozzugno@gmail.com> - 2026-01-20 17:55 +0100
Re: arm-gcc, Cortex-M0+, uint64_t and alignment David Brown <david.brown@hesbynett.no> - 2026-01-20 22:24 +0100
csiph-web