Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!news.albasani.net!eternal-september.org!feeder.eternal-september.org!.POSTED!not-for-mail From: "BartC" Newsgroups: comp.lang.java.programmer,comp.lang.c Subject: Re: Arithmetic overflow checking Date: Thu, 21 Jul 2011 12:12:43 +0100 Organization: A noiseless patient Spider Lines: 1 Message-ID: References: <015aeb15-57db-48ab-9cd4-77f8448b632f@w24g2000yqw.googlegroups.com> <2rydnez7l-H5BYnTnZ2dnUVZ_vGdnZ2d@earthlink.com> <9LWdnZH2hdfmyYvTnZ2dnUVZ_vidnZ2d@posted.palinacquisition> <3797038f-22d1-40b2-8c12-60db5a0976b8@t5g2000yqj.googlegroups.com> <289ad570-65fc-49d8-9cc8-1f15d13ff3e3@gv8g2000vbb.googlegroups.com> <_bednSTX_oyqDbvTnZ2dnUVZ7radnZ2d@brightview.co.uk> <65991dc2-9acf-4867-b54a-8569b9683320@l37g2000yqd.googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; format=flowed; charset="iso-8859-1"; reply-type=original Content-Transfer-Encoding: 7bit Injection-Date: Thu, 21 Jul 2011 11:14:13 +0000 (UTC) Injection-Info: mx04.eternal-september.org; posting-host="ySFDo36AujN+NJ7nQGUG6Q"; logging-data="13781"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18GwC4osajJnZTRXKlq/ZEG" X-MimeOLE: Produced By Microsoft MimeOLE V14.0.8089.726 In-Reply-To: <65991dc2-9acf-4867-b54a-8569b9683320@l37g2000yqd.googlegroups.com> X-Antivirus-Status: Clean X-Newsreader: Microsoft Windows Live Mail 14.0.8089.726 Importance: Normal X-Antivirus: avast! (VPS 110721-0, 21/07/2011), Outbound message Cancel-Lock: sha1:2I6m01T2RaayE/RR4A0NcsK18p4= X-Priority: 3 X-MSMail-Priority: Normal Xref: x330-a1.tempe.blueboxinc.net comp.lang.java.programmer:6334 comp.lang.c:8539 "tm" wrote in message news:65991dc2-9acf-4867-b54a-8569b9683320@l37g2000yqd.googlegroups.com... > Correct results are the most important thing you want > from an computer. > Sometimes errors are accepted, just to get maximum > performance. Or sometimes people can assume there will be no error because they know the program. If you are using C to implement another language, especially a 'softer' language where the user expects the language to hold his hand a lot more, then that is a bit of a special case. Here, problems such as trapping bounds-errors and overflows can be solved by the /implementer/ writing the appropriate C code, taking advantage of any built-in facilities for these, but not depending on them. If a badly handled bounds or overflow error occurs in the (user's) program, then that is the responsibility of the implementer; you can't blame the short-comings of C for that. People writing directly in C (who are not using C to implement another system) can't easily and elegantly make use of things such as overflow checks and array bounds checking. With an implementer however, clunky code may not be an issue (since the code will only appear in one place, or will be in generated code that no-one will ever see). (And what if the language being implemented has a range type, such as Int: 1000 .. 2000; you would surely need to check overflow *and* underflow, and you can't expect C, the OS or the hardware to give you much help here. Even more so if you have a type such as (2,4,6,10), ie. only containing those values. In this case, these checks need to be built on top of C (or whatever implementation language is used); and the same can surely be done for anything else.) -- Bartc