ImportC and #pragma pack
Walter Bright
newshound2 at digitalmars.com
Wed Sep 29 03:31:58 UTC 2021
On 9/28/2021 5:46 PM, Guillaume Piolat wrote:
> 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)
>
>
C11 6.7.5-4 sez: "The combined effect of all alignment attributes in a
declaration shall not specify an alignment that is less strict than the
alignment that would otherwise be required for the type of the object or member
being declared."
Which I interpret to mean it can be allowed as an extension.
More information about the Digitalmars-d
mailing list