在 Wed, 03 Jun 2009 15:23:45 +0800,Walter Bright
<newshou...@digitalmars.com> 写道:
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.)
I highly whether the code by utilizing this kind of semantic can be called
well-written. Porting such code to D doesn't make D any better, also it
requires a lot of effort to port. I don't know any famous C to D or C++ to
D converter. Instead, I have a working C# to D portting tool which can
port some specific code by hacking on top of SharpDevelop in only few
weeks effort. Porting C# code to D might be more attractive.
--
使用 Opera 革命性的电子邮件客户程序: http://www.opera.com/mail/