Concatenation of ubyte[] to char[] works, but assignation doesn't
Jonathan M Davis via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Tue Oct 6 05:39:49 PDT 2015
On Tuesday, October 06, 2015 09:28:27 Marc Schütz via Digitalmars-d-learn wrote:
> I see, this is a new problem introduced by `char + int = char`.
> But at least the following could be disallowed without
> introducing problems:
>
> int a = 'a';
> char b = 32;
Sure, it would be nice, but I rather doubt that Walter would go for it. He
seems to be fully in the camp of folks that think that life is better if
charater types and bool always are treated as integral types - which
unfortunately, creates fun problems like this
void foo(bool b) { writeln("bool"); }
void foo(long l) { writeln("long"); }
foo(1); // prints bool
In this case, adding on overload that takes int fixes the problem, because
integer literals default to int, but in general, it's just stupid IMHO. But
when it was brought up last, Walter didn't think that there was any problem
with it and that it was just fine to require that the int overload be added
to fix it.
> But strictly speaking, we already accept overflow (i.e. loss of
> precision) for ints, so it's a bit inconsistent to disallow it
> for chars.
Overflow is only permitted when doing arithmetic operations (when you really
can't do anything about it except maybe throw an exception, which would be
too expensive to be worth it) or when casting explicitly (in which case,
you're telling the compiler that you don't care). Overflow is never allowed
via implicit conversions.
- Jonathan M Davis
More information about the Digitalmars-d-learn
mailing list