On 07/27/2018 16:58 UTC, Owen Taylor wrote:
On Fri, Jul 27, 2018 at 13:44 UTC, Florian Weimer wrote: On 07/27/2018 13:33 UTC, John Reiser wrote:The key principle is that sizeof(foo) must be the stride of an array of foo, and the array must guarantee alignment of each element in the array. Why do you think that? If some documentation claims this is the case for individual objects, we need to fix it. struct sizes *do* have this property - they are rounded up so that arrays have the correct alignment. But that certainly doesn't imply that malloc(7) is allowed to give you unaligned memory.
What it does imply is that malloc() should only be required to align the result as if malloc()'s argument is sizeof() some C-language struct. If the call is malloc(14) then 14 == sizeof(struct xyz) implies that the alignment of struct xyz is only 2, and malloc() need only align the returned block to a 2-byte boundary. In this case: struct foo2x3 { char a[3]; char b[3]; }; sizeof(struct foo2x3) is 6 but the required alignment is only 1, not 2. malloc will align more than necessary (to a 2-byte boundary) because malloc does have complete information. To tell malloc more, especially when the caller desires stronger alignment than implied by the sizeof rule, then use posix_memalign(size, align). _______________________________________________ devel mailing list -- devel@xxxxxxxxxxxxxxxxxxxxxxx To unsubscribe send an email to devel-leave@xxxxxxxxxxxxxxxxxxxxxxx Fedora Code of Conduct: https://getfedora.org/code-of-conduct.html List Guidelines: https://fedoraproject.org/wiki/Mailing_list_guidelines List Archives: https://lists.fedoraproject.org/archives/list/devel@xxxxxxxxxxxxxxxxxxxxxxx/message/V5G7HY4CNQ3RZY3OY2XOUNO372GEJGMA/