Proposal for Implicit Conversion of Types

Don Clugston dac at nospam.com.au
Wed Apr 5 02:59:46 PDT 2006


Rioshin an'Harthen wrote:
> Proposal for Implicit Conversion of Types
> =========================================
> 
> This proposal spawned from the discussion "No more implicit
> conversion real->complex?!" between myself and Don Clugston
> after the change introduced in D version 0.150.

> archetype | types (in order of smallest to largest)
> -----------+-----------------------------------------
>  void      | void
>  bool      | bool
>  cent      | byte, short, int, long, cent
>  ucent     | ubyte, ushort, uint, ulong, ucent
>  real      | float, double, real
>  ireal     | ifloat, idouble, ireal
>  creal     | cfloat, cdouble, creal
>  dchar     | char, wchar, dchar


Very well presented! There's one aspect that I think could be a problem 
-- conversions between signed and unsigned types.
As written, that would mean that ushort -> ulong is preferred over 
ushort ->short. Since the language currently allows short and ushort to 
be interchanged without error (unless you enable warnings), I don't 
think the lookup rules can be different to that.

So I think that right now, the cent/ucent categories will need to be 
combined: if more than one such conversion is possible, it's an error.
Otherwise we end up in the 'should signed/unsigned conversions be an 
error' debate which has historically been unfruitful.



More information about the Digitalmars-d mailing list