appending newly initialized struct to array

Kenji Hara k.hara.pg at gmail.com
Wed Apr 18 00:16:12 PDT 2012


On Wednesday, 18 April 2012 at 04:55:23 UTC, Ali Çehreli wrote:
> On 04/17/2012 02:00 PM, simendsjo wrote:
>
> > Sounds like a bug. C style initializers work in other cases:
>
> I try not to use them. I think they have this 'feature' of 
> leaving unspecified members uninitialized:
>
> struct S
> {
>     int i;
>     double d;
> }
>
> void main()
> {
>     S s = { 42 };               // <-- no initializer for S.d
>     assert(s.i == 42);
>     assert(s.d == double.nan);  // <-- fails (may work for you)

You should use std.math.isNaN whether a floating point value is 
NaN.

       assert(isNaN(s.d));  // <-- success

> }
>
> Is that a bug or a feature? I might have opened it but I don't 
> remember now. :)
>
> Ali

Bye.

Kenji Hara


More information about the Digitalmars-d-learn mailing list