News for hackers. Stuff that matters.
Re:Structures in C: From Basics to Memory Alignment by colonwqbang on Thursday June 29, 2023 @07:06PM (#36528060)
I think we agree that this makes sense on some metaphysical level. The problem is that there are definitely platforms where the normal alignment isn't what you describe above. And there isn't to my knowledge a switch in GCC to force it to follow these rules on any given platform. There isn't __attribute__((natural_alignment)). But there is __attribute__((packed)).
Re:Structures in C: From Basics to Memory Alignment by wahern on Thursday June 29, 2023 @09:41PM (#36529504)
Since C11 there is _Alignas(sizeof T), forcing one of the proposed meanings for alignment, and _Alignof(T), which queries actual (i.e. natural, per another meaning) alignment. But, yeah, the argument upthread seems more about the implicit meaning of natural than anything else.
Re:Structures in C: From Basics to Memory Alignment by lsof on Friday June 30, 2023 @03:01AM (#36531467)
On that note, something that caught me off guard once is that C11 _Alignof and GCC __alignof__ can differ: for example in 32-bit x86 __alignof__(double) == 8 but _Alignof(double) == 4; however __alignof__(struct { double d; }) == 4. Apparently __alignof__ gives the preferred alignment whereas _Alignof gives the alignment required by ABI.