From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: 103376,803d147296719896 X-Google-Attributes: gid103376,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news2.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!local01.nntp.dca.giganews.com!nntp.comcast.com!news.comcast.com.POSTED!not-for-mail NNTP-Posting-Date: Mon, 04 Jun 2007 23:10:59 -0500 From: tmoran@acm.org Newsgroups: comp.lang.ada Subject: Re: Puzzling small piece of code - exception block essentially used as goto References: X-Newsreader: Tom's custom newsreader Message-ID: Date: Mon, 04 Jun 2007 23:10:59 -0500 NNTP-Posting-Host: 24.6.140.189 X-Trace: sv3-vEC3llLWRcilWOV9W5UDkLaK8TIx9hlJKuLPyX5dknfvyNgC3qY7TECAiASbd2Kn/S7TrV+IeLIjI4H!mUDIGjDv41/1m37OBcoinSB09oMzhMG4UYEHwZ8wBl80ysteRdBuascDyt6qjU9wsxhOS+6+mI5O!J3u+8Qd9qp8onVSCTfOABfX5VT5P X-Complaints-To: abuse@comcast.net X-DMCA-Complaints-To: dmca@comcast.net 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.34 Xref: g2news1.google.com comp.lang.ada:16068 Date: 2007-06-04T23:10:59-05:00 List-Id: > > Without knowing the details of the types of the variables used, I > > can't say. > > Here are the ranges for the variables (all are integers): > > Hour_Delta: -9999*60..9999*60 > New_Hour: 0..2^32 > Hour: 0..2^32 > > Relative_Time : constant := 0; And what is the value of Max_Hour_Delta? Another way to look at that code is to observe that the only way out of the loop is to not raise Constraint_Error, ie, New_Hour is within +-9999*60 of Hour (that *60 rather suggests the units are minutes, not hours as one might assume fron the names). If that's not true at first, the code adjusts Hour by steps of Max_Delta_Hour, hopefully in the direction of New_Hour. If it doesn't overshoot, Hour will eventually be in range, at which time it will be set to the value of New_Hour. So the code essentially says: if Max_Delta_Hour < 0 then burn some CPU time; -- move Hour ever farther from New_Hour raise Constraint_Error; -- till it hits a limit elsif Max_Delta_Hour = 0 then sit forever in infinite loop, never changing Hour; elsif Max_Delta_Hour in > 2 * 9999*60 + 1 + ( abs(New_Hour-Hour) mod (9999*60+1) ) then oscillate forever between Hour too positive and Hour too negative; else burn some CPU time; end if; Hour := New_Hour; (if I did my algebra correctly). So replacing the whole thing by "Hour := New_Hour;" probably does what the original programmer wanted.