Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!eternal-september.org!feeder.eternal-september.org!.POSTED!not-for-mail From: Gene Wirchenko Newsgroups: comp.lang.java.programmer Subject: Re: Arithmetic overflow checking Date: Fri, 08 Jul 2011 10:27:41 -0700 Organization: A noiseless patient Spider Lines: 41 Message-ID: <09fe171s46ilvq9qmn254dctunm6noh0ps@4ax.com> References: <015aeb15-57db-48ab-9cd4-77f8448b632f@w24g2000yqw.googlegroups.com> <1f9c17dltrhlmhifuigoa914477r4rg1e1@4ax.com> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit Injection-Info: mx04.eternal-september.org; posting-host="7Qrvczazr82YckO5XW8Vtw"; logging-data="21712"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/9rvQyxqSkb3RS95/WeL0DH6Yk+6AVerA=" X-Newsreader: Forte Agent 4.2/32.1118 Cancel-Lock: sha1:Ce65GTGl8biDi4VUnkAxq+EIyGw= Xref: x330-a1.tempe.blueboxinc.net comp.lang.java.programmer:5990 On Thu, 7 Jul 2011 17:29:42 -0700 (PDT), lewbloch wrote: >On Jul 7, 5:12 pm, Gene Wirchenko wrote: >> On Thu, 07 Jul 2011 14:53:50 -0700, Patricia Shanahan >> wrote: >> >> [snip] >> >> >I think the problem is more a matter of software knowing when overflow >> >should and should not be treated as an error. >> >>      Exactly.  C does not do that sort of checking, and the meme has >> spread widely.  I would much prefer to have things blow up when wrong >> than not blow up.  It makes for smaller messes. >> > >the problem with that statement is that it's not wrong for Java >primitive integer types to wrap around. Java is designed to behave that way. That does not mean that it is not wrong. A garrot is designed to be a murder weapon. That it was designed for that does not make any murder committed with a garrot any less wrong. >It is, in fact, wrong for them to throw an overflow exception, as many >have pointed out in this thread. It is designed to behave like that. That behaviour is often wrong from the point of view of ensuring program correctness. C allows wraparound with unsigned (which I wish Java had) integers. An overflow with signed integers results in undefined behaviour. C's semantics are better than those of Java in this regard. They should be better: throw an error. Sincerely, Gene Wrichenko