[Issue 12601] New: Nested functions and properties increase size of struct.
via Digitalmars-d-bugs
digitalmars-d-bugs at puremagic.com
Sun Apr 20 01:21:20 PDT 2014
https://issues.dlang.org/show_bug.cgi?id=12601
Issue ID: 12601
Summary: Nested functions and properties increase size of
struct.
Product: D
Version: D2
Hardware: x86_64
OS: Linux
Status: NEW
Severity: major
Priority: P1
Component: DMD
Assignee: nobody at puremagic.com
Reporter: mrdarksys at gmail.com
Hi, all.
I found next unexpected behaviour: Nested functions and properties increase
size of struct.
[CODE]
import std.stdio;
int main()
{
struct A
{
ushort variable;
}
struct B
{
ushort variable;
}
struct C
{
ushort variable;
@property int var()
{
return variable;
}
}
A a;
B b;
C c;
@property var(B v)
{
return v.variable;
}
writeln("A.sizeof: ", a.sizeof);
writeln("B.sizeof: ", b.sizeof);
writeln("C.sizeof: ", c.sizeof);
return 0;
}
[/CODE]
[OUTPUT]
A.sizeof: 2
B.sizeof: 2 /// property for this struct does not change size
C.sizeof: 16 /// <- real size should be 2 (has nested function-property)
[/OUTPUT]
Reproduced on:
- DMD 2.065
- GDC 4.8.2
This behaviour is founded when used next code:
[CODE]
struct FrameHeader
{
mixin(
bitfields!(
bool, "fin", 1,
bool, "rsv1", 1,
bool, "rsv2", 1,
bool, "rsv3", 1,
FrameOpcode, "opcode", 4,
bool, "mask", 1,
ubyte, "payloadLength", 7
)
);
}
long receive(void[] value)
{
/// reading is here
}
long receive(T)(ref T value) if (is(T == struct))
{
return receive((cast(void*)&value)[0..value.sizeof]); /// try read 16
bytes instead of 2.
}
// ...
FrameHeader frameHeader;
receive(frameHeader);
[/CODE]
--
More information about the Digitalmars-d-bugs
mailing list