D, windows developement, frustration and fish

ketmar via Digitalmars-d digitalmars-d at puremagic.com
Sun Feb 1 03:58:22 PST 2015


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.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 181 bytes
Desc: not available
URL: <http://lists.puremagic.com/pipermail/digitalmars-d/attachments/20150201/fa10b7b9/attachment.sig>


More information about the Digitalmars-d mailing list