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

max haughton maxhaton at gmail.com
Thu May 19 00:55:50 UTC 2022


On Thursday, 19 May 2022 at 00:27:24 UTC, Walter Bright wrote:
> On 5/18/2022 3:31 PM, H. S. Teoh wrote:
>> 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.
>
> People routinely manipulate chars as integer types, for 
> example, in converting case. Making them not integer types 
> means lots of casting will become necessary, and overall that's 
> a step backwards.

People do indeed (I'd question whether it's routine in a good D 
program, I'd flag it in code review) manipulate characters as 
integers, but I think there's something to be said for forcing 
people to go char -> suitable integer -> char.

We have u/byte, largely for descriptive purposes already, 
personally I try to use them for calculation even if the byte's 
value is from a char.


More information about the Digitalmars-d mailing list