davidl wrote:
?? Wed, 03 Jun 2009 10:58:32 +0800??Tim Matthews
<[email protected]> ????:
davidl wrote:
I mean the first behavior can cause problems.
Ohh sorry.
I doubt any coder would try to get that result by writing that piece
of code. I ported some C# source to D, and I got this semantic
different issue.
It is probably mostly used for dealing with binary data but D has no
other way of specifying a number that is only 1 byte except the char
but that would be a misuse of the type system unless ported from
c/c++. Just a few gotchas off the top of my head:
D C#
------------
ubyte Byte
byte SByte
wchar Char
Perhaps, it's because of my mistranslating all Byte to byte directly.
Yes. Yet there's an issue here -- EVERYONE expects 'byte' to be
unsigned. Walter even forgot it when he did the first release of htod.
The uses for signed bytes are so rare, that any use of 'byte' is highly
likely to be an error.
Nonetheless, the first behavior is not impressive. I innately dislike
that. Because I try to deal with a type with one byte by using Or
operator, I get it promoted to int. That implicitly cast sounds awful.
I agree, it's bug-prone.
Ideally, we'd disallow implicit widening casts for signed types in
logical operations. But can that be done without creating too many
language quirks?