Skip to main content
6 events
when toggle format what by license comment
Sep 14, 2023 at 4:34 comment added Nate Eldredge "Some implementations might wish to have all struct fields in the order they're declared": The C standard effectively requires this; 6.7.2.1p15 says the addresses of struct members must increase in the order in which they are declared.
Sep 9, 2023 at 9:47 comment added kaya3 @Barmar No ─ for example, a value sized 1 byte would be aligned at any address, whereas a 4-byte-sized value would be aligned at addresses which are a multiple of 4. Otherwise you would not be able to store an array compactly and take a pointer to one of its elements. So for example a struct of two 32-bit ints on a 64-bit machine would only require 8 bytes to properly align both fields, but would require 16 bytes if either or both fields require atomic accesses which can't be done at the sub-word level on a given machine.
Sep 8, 2023 at 21:25 comment added Barmar "the target architecture only supports atomic accesses of whole words." Isn't that padding implied by "requires to ensure that all of the members are properly aligned"?
Sep 8, 2023 at 21:24 comment added Barmar If you need compatibility with some specification, you usually do that by declaring explicit members for those extra spaces.
Jun 14, 2023 at 15:03 history edited kaya3 CC BY-SA 4.0
added 206 characters in body
Jun 13, 2023 at 19:56 history answered kaya3 CC BY-SA 4.0