digitalmars.D.learn - Why does disabling a struct's postblit increase its size in memory?
- Per =?UTF-8?B?Tm9yZGzDtnc=?= (10/10) Mar 02 2024 Why does disabling a struct's postblit increase its sizeof by one
- kinke (4/13) Mar 02 2024 Not according to run.dlang.io, for all available DMD versions.
- Per =?UTF-8?B?Tm9yZGzDtnc=?= (2/5) Mar 02 2024 Ahh. Yes. Indeed. My mistake. Thanks.
- Per =?UTF-8?B?Tm9yZGzDtnc=?= (3/8) Mar 02 2024 Thanks. Neither my websearches nor ChatGPT plus couldn't figure
- Paul Backus (24/33) Mar 03 2024 FYI, you can dump the layout of a struct, including hidden
Why does disabling a struct's postblit increase its sizeof by one
word?
The following holds:
```d
struct S { disable this(this); int _; }
struct T { int _; }
static assert(S.sizeof == 16);
static assert(T.sizeof == int.sizeof);
```
. Why is this needed?
Mar 02 2024
On Saturday, 2 March 2024 at 15:25:48 UTC, Per Nordlöw wrote:
Why does disabling a struct's postblit increase its sizeof by
one word?
The following holds:
```d
struct S { disable this(this); int _; }
struct T { int _; }
static assert(S.sizeof == 16);
static assert(T.sizeof == int.sizeof);
```
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.
Mar 02 2024
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.
Mar 02 2024
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:Thanks. Neither my websearches nor ChatGPT plus couldn't figure that out.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.
Mar 02 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: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 ```On Saturday, 2 March 2024 at 19:11:42 UTC, kinke wrote:Thanks. Neither my websearches nor ChatGPT plus couldn't figure that out.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.
Mar 03 2024








Paul Backus <snarwin gmail.com>