Don wrote:
I agree, it's bug-prone.

Any two's complement arithmetic system, with types of different sizes and signed-ness, is going to have quirks. It's inescapable. Back when C was standardized in the 80's, there was a huge debate about whether to use signed-preserving rules or value-preserving rules. After much debate, it came down to pick set A of problems or set B of problems. The committee picked one (value preserving) and moved on.

http://books.google.com/books?id=yxLISD0TAbEC&pg=PA35&lpg=PA35&dq=signed+preserving+versus+value+preserving+integral+promotion+rules&source=bl&ots=tCRBjyS4jC&sig=VCVgyAr9u0ItJbcZ5r-fLnxGmX4&hl=en&ei=riMmSufaCafcswO4vbWUBg&sa=X&oi=book_result&ct=result&resnum=9


Ideally, we'd disallow implicit widening casts for signed types in logical operations. But can that be done without creating too many language quirks?


The problem with changing the rules is that the value preserving rules are now deeply ingrained into how C (and C++) code is written. Changing them would mean that translating complex code from C to D may produce silent changes in behavior. I believe this would be very bad for D because it means people would not be able to translate such code to D.

(After all, it's one thing to translate, say, an encryption program from C to D. It's quite another thing to understand it well enough to be able to debug it, or even verify that it is working correctly.)

Reply via email to