[GSoC] Header Generation for C/C++
kinke
noone at nowhere.com
Tue Jul 30 19:23:34 UTC 2019
On Tuesday, 30 July 2019 at 18:40:04 UTC, Eduard Staniloiu wrote:
> 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
I've only found 2 explicit alignments in the *frontend* files
(dmd/{libomf,scanmscoff}.d aren't part of the frontend):
1) dmd/root/longdouble.d:
-----
struct longdouble_soft
{
// DMD's x87 `real` on Windows is packed (alignof = 2 ->
sizeof = 10).
align(2) ulong mantissa;
ushort exp_sign;
}
-----
2) dmd/expression.d:
-----
align(8) union __AnonStruct__u { ... }
-----
These 2 instances can be altered not to require any explicit
alignment. Then there wouldn't be any current need for align()
support.
Instance 1, `longdouble_soft`, is only relevant for MSVC. It
could consist of data `ushort[4] mantissa_; ushort exp_sign`
(natural alignment of 2 and size 10) and feature a `ref ulong
mantissa()` property performing a reinterpret-cast.
Instance 2 only needs an additional `long __for_alignment_only`
union member (union alignment is already handled like this in
another union I don't remember OTOH).
More information about the Digitalmars-d
mailing list