On Sun, 01 Feb 2015 11:49:29 +0000, Vladimir Panteleev wrote: > On Sunday, 1 February 2015 at 11:44:12 UTC, ketmar wrote: >> yep, without properly compiled libraries there are constant complains >> about missing structure initalizers. i got rid of that with simple >> template, and wrote "auto pi = zeroed!PROCESS_INFORMATION;" and alikes >> instead. i'm not using batch compilation, so that was easier than >> building all the libs. ;-) > > This should work too: > > PROCESS_INFORMATION pi = void;
that was my template does, actually. ;-) public T zeroed(T) () if (__traits(isPOD, T)) { import core.stdc.string : memset; T res = void; memset(&res, 0, res.sizeof); return res; } due to compiler optimisation of struct returns this is almost the same as inlining call to `memset()`. > Or, if you actually need it initialized: > > PROCESS_INFORMATION pi = {}; > > I did not expect the above to work, but it does. i wonder why it works. > (N.B.: PROCESS_INFORMATION is all-zero so it doesn't actually have a > .init, test with a structure which has non-zero defaults for fields.) yet dmd still insists on having that `.init`. and there are no non-zero defaults for winapi bindings, so i'm fine with such hacks. ;-) my own modules are built properly by my build system, so there are `.init`s for all necessary structs.
signature.asc
Description: PGP signature