Array initializers and inheritance
Bill Baxter
dnewsgroup at billbaxter.com
Sun Oct 29 21:42:04 PST 2006
Chris Nicholson-Sauls wrote:
> Frank Benoit (keinfarbton) wrote:
>> I think, the array initialization feature is not so nice. The array
>> takes its type from the type of the first initializer. This is
>> absolutely ugly.
>
> You are correct that it takes its type from the first element. In the
> vast majority of cases (personal experience, might not be general) this
> hasn't been a problem. Still, I do feel a little antsy sometimes about
> putting that cast() at the beginning.
To me that is fairly surprising behavior. I would expect the compiler
to look at *all* the values in the array literal and pick the type to
use based on standard promotion rules ("integer promotions" and "usual
arithmetic conversions" from http://www.digitalmars.com/d/type.html).
I.e. [1, 2, 3, 4.0] should be double[4], not int[4].
Just like 1+2+3+4.0 is a double and not and int.
--bb
More information about the Digitalmars-d-learn
mailing list