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

Steven Schveighoffer schveiguy at gmail.com
Thu May 19 00:47:16 UTC 2022


On 5/18/22 6:31 PM, H. S. Teoh wrote:
> 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.

If you were to ask me, I'd say prohibit implicit conversions between 
char types and any other types, including other char types. converting 
char to dchar isn't correct.

But I have little hope for it, as Walter treats a boolean as an integer.

-Steve


More information about the Digitalmars-d mailing list