[GSoC] Header Generation for C/C++

Eduard Staniloiu edi33416 at gmail.com
Tue Jul 30 18:40:04 UTC 2019


On Tuesday, 30 July 2019 at 18:00:44 UTC, Manu wrote:
> On Tue, Jul 30, 2019 at 8:10 AM Andrei Alexandrescu via 
> Digitalmars-d <digitalmars-d at puremagic.com> wrote:
>>
>> On 7/30/19 10:50 AM, Eduard Staniloiu wrote:
>> >[...]
>>
>> Better yet:
>>
>> #if defined(__GNUC__) || defined(__clang__)
>>      #define BEGIN_PACK(n) __attribute__((packed, aligned(n)))
>> #elif defined(_MSC_VER)
>>      #define BEGIN_PACK(n) __declspec(align(n))
>> #elif defined(__DMC__)
>>      #define BEGIN_PACK(n) #pragma pack(push, n)
>> #endif
>>
>> #if defined(__DMC__)
>>      #define END_PACK() #pragma pack(pop)
>> #else
>>      #define END_PACK()
>> #endif
>
> This is precisely what I was just about to propose ;)

Will use this, but my question still stands:
__attribute__ packed or not?

Given the following struct
```
struct S
{
     int x;
     char y;
}
```

With `struct __attribute__((packed, aligned(8))) S` -> sizeof(S) 
is 5

With `struct __attribute__((aligned(8))) S` -> sizeof(S) is 8


More information about the Digitalmars-d mailing list