disabling unary "-" for unsigned types

bearophile bearophileHUGS at lycos.com
Mon Feb 15 17:50:40 PST 2010


Some of the ways C uses fixnums, its undefined situations, are bad today. The Ada language is not handy to use, but it shows that if you want to create reliable software able to fly planes, you want a language with a more tidy arithmetic than C.

And I am not talking about multiprecision numbers here, there are many situations where fixnums are enough (even if I think in any D program there are some or many places where using a fixnum is a premature optimization).

In a tidy language if you have an integral value represented with a fixed number of bits (like a D uint), and you try to assign it a value (like a -1) outside the range of the values it can represent, you have a bug. Or you want modulo arithmetic, but you have to help the compiler tell such two situations apart.

You can't think just about what DMD2 is/does today: once integral overflow tests are added to a future D2 compiler, don't you want a runtime error if you assign to a number a value outside the range of the possible values it can represent (like a negative value to an unsigned value)?

I am not sure.

Bye,
bearophile



More information about the Digitalmars-d mailing list