Member function increases size of a struct defined in a function - is this a bug?
Ferdinand Majerech
dummy at gmail.com
Fri Feb 7 12:36:23 UTC 2020
Ran into this while playing around with std.bitmanip.bitfields
for packet protocol fields.
```
void fun()
{
struct InnerFun
{
ubyte a;
void fun() {}
}
struct InnerNoFun
{
ubyte a;
}
pragma(msg, "InnerFun ", InnerFun.sizeof); // prints 16
pragma(msg, "InnerNoFun ", InnerNoFun.sizeof); // prints 1
}
```
Size of InnerFun is 16 while size of InnerNoFun is 1 - this took
a while to debug as I could not figure out why my protocol
headers are unexpectedly large - `align(1)` did not help.
This does not happen if the structs are defined outside of a
function.
Is this the result of some D feature?
I can imagine this could happen if InnerFun had a silently added
context pointer, but I don't know of such a feature in D.
Reported here:
https://issues.dlang.org/show_bug.cgi?id=20564
remove if this is expected behavior.
More information about the Digitalmars-d
mailing list