Path: csiph.com!x330-a1.tempe.blueboxinc.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!border3.nntp.dca.giganews.com!Xl.tags.giganews.com!border1.nntp.dca.giganews.com!nntp.giganews.com!local2.nntp.dca.giganews.com!nntp.posted.palinacquisition!news.posted.palinacquisition.POSTED!not-for-mail NNTP-Posting-Date: Tue, 19 Jul 2011 01:22:16 -0500 Date: Mon, 18 Jul 2011 23:22:14 -0700 From: Peter Duniho User-Agent: Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.5; en-US; rv:1.9.2.17) Gecko/20110414 Thunderbird/3.1.10 MIME-Version: 1.0 Newsgroups: comp.lang.java.programmer Subject: Re: Arithmetic overflow checking References: <015aeb15-57db-48ab-9cd4-77f8448b632f@w24g2000yqw.googlegroups.com> <2rydnez7l-H5BYnTnZ2dnUVZ_vGdnZ2d@earthlink.com> <9LWdnZH2hdfmyYvTnZ2dnUVZ_vidnZ2d@posted.palinacquisition> <4e24f754$0$311$14726298@news.sunsite.dk> In-Reply-To: <4e24f754$0$311$14726298@news.sunsite.dk> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit Message-ID: Lines: 23 X-Usenet-Provider: http://www.giganews.com NNTP-Posting-Host: 50.46.118.188 X-Trace: sv3-HprYEvwVRQyL3JsBODfF2fOGOr98iUroYWNIr9k7lp4ho1kxoiDhuSlQsEdMJImDCETW+kB0U/FQNYl!+KCvAZqLXOJ5jZeJ8kmMPXfEG8oDCAHzu3S45xz9snDanZXoePNKxCwCY7mVz2x64A9PVQz1IacP!r2mWzBOxIVE8EK/czVj1qi3uKv250thvqiROGxdLEDg= X-Complaints-To: abuse@iinet.com X-DMCA-Complaints-To: abuse@iinet.com X-Abuse-and-DMCA-Info: Please be sure to forward a copy of ALL headers X-Abuse-and-DMCA-Info: Otherwise we will be unable to process your complaint properly X-Postfilter: 1.3.40 X-Original-Bytes: 2624 Xref: x330-a1.tempe.blueboxinc.net comp.lang.java.programmer:6280 On 7/18/11 8:17 PM, Arne Vajhøj wrote: > [...] >> I did a quick check of the C# variant when it was mentioned here, and >> this is how they do it: >> >> int result = checked( a + b - c ); >> >> [...] > > Just note that C# is a bit more rich than that: > > default and compiled with /checked- => checked(expression) and > checked { } do overflow check for expression / block but do not > for the rest > > compiled with /checked+ => unchecked(expression) and > unchecked { } do not overflow check for expression / block > but do for the rest As long as we're calling out the specifics: it may be important to know that in C#, statically computable expressions (more specifically, those that contain only constants) are always checked unless in an explicit "unchecked" block, even if the default setting is used.