D arithmetic problem

Don nospam at nospam.com
Wed Jun 3 23:00:27 PDT 2009


bearophile wrote:
> Denis Koroskin:
>> Shouldn't bitwise operations be disallowed on signed types at all?
> 
> It sounds OK to me, do Don & Walter agree?

Hmm. If you are doing bitwise operations, you are treating the number as 
unsigned, no doubt about it. Some observations:

* The use of -1 for "all bits set" is in widespread use and is important.

ushort x ^= -1;
uint y ^= -1;
ulong z ^= -1;
probably needs to remain valid.
But then consider
  (x ^ -1) + y

What is the type of x^-1 ? Is it ushort? Or int?

* A lot of existing C code uses bitwise operations on ints.
* size_t had better be unsigned!







> 
> Bye,
> bearophile



More information about the Digitalmars-d mailing list