Why does disabling a struct's postblit increase its size in memory?

Paul Backus snarwin at gmail.com
Sun Mar 3 22:37:02 UTC 2024


On Saturday, 2 March 2024 at 19:29:47 UTC, Per Nordlöw wrote:
> On Saturday, 2 March 2024 at 19:28:08 UTC, Per Nordlöw wrote:
>> On Saturday, 2 March 2024 at 19:11:42 UTC, kinke wrote:
>>> Not according to run.dlang.io, for all available DMD 
>>> versions. Perhaps your tested `S` was nested in some 
>>> function/aggregate and so had an implicit context pointer.
>>
>> Ahh. Yes. Indeed. My mistake. Thanks.
>
> Thanks. Neither my websearches nor ChatGPT plus couldn't figure 
> that out.

FYI, you can dump the layout of a struct, including hidden 
fields, by iterating over its `.tupleof` property:

```d
void main()
{
     struct S
     {
         @disable this(this);
         int n;
     }

     static foreach (field; S.tupleof)
         pragma(msg,
             typeof(field).stringof, " ",
             __traits(identifier, field), " ",
             "at ", field.offsetof
         );
}
```

This example prints out

```
int n at 0LU
void* this at 8LU
```


More information about the Digitalmars-d-learn mailing list