Should you be able to initialize a float with a char?

H. S. Teoh hsteoh at quickfur.ath.cx
Wed May 18 22:31:20 UTC 2022


On Wed, May 18, 2022 at 10:11:34PM +0000, max haughton via Digitalmars-d wrote:
> For example:
> 
> float x = 'a';
> 
> Currently compiles. I had no idea that it does but I was implementing
> this pattern in SDC and lo and behold it does (and thus sdc has to
> support it).
> 
> Should it? Implicit conversions and implicit-anything around floats
> seem to be very undocumented in the specification too.

If you were to ask me, I'd say prohibit implicit conversions between
char and non-char types. Otherwise you end up with nonsense code like
the above.

But IIRC, the last time this conversation came up, Walter's view was
that they are all integral types and therefore should be
interconvertible.  The topic at the time was bool vs int, but the same
principle holds in this case.


T

-- 
MSDOS = MicroSoft's Denial Of Service


More information about the Digitalmars-d mailing list