[GSoC] Header Generation for C/C++
Gregor Mückl
gregormueckl at gmx.de
Fri Aug 2 13:17:46 UTC 2019
On Tuesday, 30 July 2019 at 14:50:15 UTC, Eduard Staniloiu wrote:
> Another question is how should `align(n)` be generated. See the
> following two:
>
> 1) __attribute__((packed, aligned(n)))
>
> or
>
> 2) __attribute__((aligned(n)))
>
> Note the missing `packed` between 1) and 2)
>
> Currently (on GH) the entire generated output looks like this
>
> struct
> #if defined(__GNUC__) || defined(__clang__)
> __attribute__((packed, aligned(8)))
> #elif defined(_MSC_VER)
> __declspec(align(8))
> #elif defined(__DMC__)
> #pragma pack(push, 8)
> #endif
> MyStruct
> {
> /* fields */
> }
> #if defined(__DMC__)
> #pragma pack(pop)
> #endif
This only covers structure packing rules, right? So alignment of
the aggregate as a whole (equivalent to C++ alignas(n) statement)
is out of scope?
If so,
#pragma pack(push,n)
and
#pragma pack(pop,n)
work on MSVC, GCC and clang in my experience. DMC is documented
to have the same behavior. So you should be able to dispense with
the #ifdef's completely.
More information about the Digitalmars-d
mailing list