What's the replacement for this array initialization: "ubyte[4096] window =0;"

Marco Leise Marco.Leise at gmx.de
Thu Feb 21 20:10:21 PST 2013


  struct ExpandData
  {
    /// Last seen bytes during expansion.
    ubyte[4096] window = 0;
    ...
  }


I noticed in 2.062 this code doesn't work anymore. The
compiler still does the initial type conversion of 0 from int
to ubyte, but the assignment fails with:

  cannot implicitly convert expression (cast(ubyte)0u) of type
  ubyte to ubyte[4096LU]

So I'm wondering to do this now. I want to be explicit so a
reader knows I explicitly set the initial value of this array
in that structure to all zeros. My argument is that D
initializes not with the most convenient, but the most wrong
value in order to provoke reproducible errors. So in general
you should initialize to sane values.

-- 
Marco



More information about the Digitalmars-d-learn mailing list