=void in struct definition
Shachar Shemesh
shachar at weka.io
Wed Apr 11 07:45:40 UTC 2018
On 09/04/18 14:22, Jonathan M Davis wrote:
> On Monday, April 09, 2018 14:06:50 Shachar Shemesh via Digitalmars-d wrote:
>> struct S {
>> int a;
>> int[5000] arr = void;
>> }
>>
>> void func() {
>> S s;
>> }
>>
>> During the s initialization, the entire "S" area is initialized,
>> including the member arr which we asked to be = void.
>>
>> Is this a bug?
>
> It looks like Andrei created an issue about it as an enhancement request
> several years ago:
>
> https://issues.dlang.org/show_bug.cgi?id=11331
>
> - Jonathan M Davis
>
Except that issue talks about default constructed objects. My problem
happens also with objects constructed with a constructor:
extern(C) void func(ref S s);
struct S {
uint a;
int[5000] arr = void;
this(uint val) {
a = val;
}
}
void main() {
auto s = S(12);
// To prevent the optimizer from optimizing s away
func(s);
}
$ ldc2 -c -O3 -g test.d
$ objdump -S -r test.o | ddemangle > test.s
0000000000000000 <_Dmain>:
}
}
void main() {
0: 48 81 ec 28 4e 00 00 sub $0x4e28,%rsp
7: 48 8d 7c 24 04 lea 0x4(%rsp),%rdi
auto s = S(12);
c: 31 f6 xor %esi,%esi
e: ba 20 4e 00 00 mov $0x4e20,%edx
13: e8 00 00 00 00 callq 18 <_Dmain+0x18>
14: R_X86_64_PLT32 memset-0x4
a = val;
18: c7 04 24 0c 00 00 00 movl $0xc,(%rsp)
1f: 48 89 e7 mov %rsp,%rdi
// To prevent the optimizer from optimizing s away
func(s);
22: e8 00 00 00 00 callq 27 <_Dmain+0x27>
23: R_X86_64_PLT32 func-0x4
}
27: 31 c0 xor %eax,%eax
29: 48 81 c4 28 4e 00 00 add $0x4e28,%rsp
30: c3 retq
Notice the call to memset.
Shachar
More information about the Digitalmars-d
mailing list