digitalmars.D.learn - need help to work around float union non-zero init
- Dakota (17/17) Sep 20 I need my struct defined as `isZeroInit`, so can I can import
- IchorDev (5/6) Sep 20 I've sent issues for compiler bugs and had them fixed within the
- monkyyy (17/34) Sep 20 ```d
- Nick Treleaven (10/28) Sep 20 Write `= void` for each field with non-zero init:
- Dakota (3/5) Sep 23 Thanks your all for the tips, void solution fix me problem.
I need my struct defined as `isZeroInit`, so can I can import them as `di` file. (this also reduce build size) But I find this problem with float inside union: ```d struct test_t { union { int i32; float f32; } } static assert(__traits(isZeroInit, test_t) ); ``` ```sh Error: static assert: `__traits(isZeroInit, test_t)` is false ``` I consider this is compiler bug (it may take years to get fixed), so I am here to ask any way to workaround this problem?
Sep 20
On Friday, 20 September 2024 at 09:38:54 UTC, Dakota wrote:I consider this is compiler bug (it may take years to get fixed)I've sent issues for compiler bugs and had them fixed within the next release—about month, not years. Also yes, this seems to be a compiler bug; unless there's some special case missing from the spec.
Sep 20
On Friday, 20 September 2024 at 09:38:54 UTC, Dakota wrote:I need my struct defined as `isZeroInit`, so can I can import them as `di` file. (this also reduce build size) But I find this problem with float inside union: ```d struct test_t { union { int i32; float f32; } } static assert(__traits(isZeroInit, test_t) ); ``` ```sh Error: static assert: `__traits(isZeroInit, test_t)` is false ``` I consider this is compiler bug (it may take years to get fixed), so I am here to ask any way to workaround this problem?```d union somevalue{ int i32; float f32; } struct test_t{ somevalue a=void; } static assert(__traits(isZeroInit, test_t)); unittest{ test_t foo; assert(foo.a.i32==0); } ``` this version compiles, but you probably need to provide more details
Sep 20
On Friday, 20 September 2024 at 09:38:54 UTC, Dakota wrote:I need my struct defined as `isZeroInit`, so can I can import them as `di` file. (this also reduce build size) But I find this problem with float inside union: ```d struct test_t { union { int i32; float f32; } } static assert(__traits(isZeroInit, test_t) ); ``` ```sh Error: static assert: `__traits(isZeroInit, test_t)` is false ``` I consider this is compiler bugFix: https://github.com/dlang/dmd/pull/16858(it may take years to get fixed), so I am here to ask any way to workaround this problem?Write `= void` for each field with non-zero init: ``` union { int i32; float f32 = void; } ``` Thanks to Dennis for the workaround.
Sep 20
On Friday, 20 September 2024 at 16:21:10 UTC, Nick Treleaven wrote:On Friday, 20 September 2024 at 09:38:54 UTC, Dakota wrote: Thanks to Dennis for the workaround.Thanks your all for the tips, void solution fix me problem.
Sep 23