[GSoC] Header Generation for C/C++

Eduard Staniloiu edi33416 at gmail.com
Thu Sep 5 11:25:47 UTC 2019


On Friday, 2 August 2019 at 13:17:46 UTC, Gregor Mückl wrote:
> 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.

I missed your reply. Sorry about that.

`#pragma pack(push/pop, n)` was initially used, but when testing 
it didn't have the same behaviour as `__attribute__((packed, 
aligned(n)))` so I ended up with the entire `#ifdef` tree above.

I could generate `alignas(n)` when the user compiles with 
`-extern-std=c++11` and above, but I'm currently working on 
correctly generating the ctors and dtors declarations.


More information about the Digitalmars-d mailing list