Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!news.albasani.net!nuzba.szn.dk!news.szn.dk!pnx.dk!dotsrc.org!filter.dotsrc.org!news.dotsrc.org!not-for-mail Date: Mon, 18 Jul 2011 23:17:39 -0400 From: =?ISO-8859-1?Q?Arne_Vajh=F8j?= User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:5.0) Gecko/20110624 Thunderbird/5.0 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> In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Lines: 39 Message-ID: <4e24f754$0$311$14726298@news.sunsite.dk> Organization: SunSITE.dk - Supporting Open source NNTP-Posting-Host: 72.192.23.157 X-Trace: news.sunsite.dk DXC=:P9`@M=4Md7H=^0YSB=nbEKnk;D938Hb_SZ9>JPe3\kP5EU1KBm9cfh9BS4M2;kT<[:>[1^\^m:T0bBg=;VU8@m4o=D? X-Complaints-To: staff@sunsite.dk Xref: x330-a1.tempe.blueboxinc.net comp.lang.java.programmer:6279 On 7/9/2011 10:46 AM, markspace wrote: > On 7/9/2011 2:58 AM, rop rop wrote: >> I also think not, in the general case... >> But you could also have an annotation argument, like >> >> @CheckForOverflow(allTheWayDown=true) >> or >> @CheckForOverflow(allTheWayDown=false) > > > 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 ); > > In other words is a key word. Since Java can't really do this easily, > I'd be in favor of using an existing key word and extending it. For > example, the key word "try" can't ever appear currently as a class name > or package name in any program, so we could do this: > > int result = try.checked( a + b - c ); > > Which at least makes sense to me as one reads the code; i.e., it's > literate programming. One could, I suppose, also extend the syntax where > an annotation can be used, but this might have side effects also. For > example, it might be hard to support these new user defined annotations > in the general case. 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 Arne