ImportC and #pragma pack

Guillaume Piolat first.name at notexisting.com
Wed Sep 29 00:46:41 UTC 2021


On Tuesday, 28 September 2021 at 23:16:28 UTC, Walter Bright 
wrote:
>
> Anyhow, pointing out non-standard constructs that can be 
> replaced with standard ones


But _Alignas strictly can't replace #pragma pack.

D's align(), C's _Alignas, and #pragma pack have 3 different 
semantics.

See https://ideone.com/bv6mET

- #pragma pack can only _reduce_ alignment requirements within a 
struct, NOT introduce additional padding

- _Alignas, contrarily, can only be used to _increase_ alignment 
and introduce padding, but cannot reduce the natural alignment of 
a field.

- D's align can both reduce and increase field alignment, which 
is of course the better option (https://ideone.com/TLSZUO)




More information about the Digitalmars-d mailing list