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=0.2 required=5.0 tests=BAYES_00,INVALID_MSGID, REPLYTO_WITHOUT_TO_CC autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,c7d533acec91ae16 X-Google-Attributes: gid103376,public From: Marin David Condic Subject: Re: Question for the folks who designed Ada95 Date: 1999/04/29 Message-ID: <3728D2E6.C915F89C@pwfl.com>#1/1 X-Deja-AN: 472482892 Content-Transfer-Encoding: 7bit Sender: condicma@bogon.pwfl.com References: <7g2qu4$ca4$1@usenet.rational.com> <7g6upj$v5c$1@nnrp1.dejanews.com> <3727EC39.E460C803@rocketmail.com> <7g9r16$gll$1@nnrp1.dejanews.com> <925410775.940.21@news.remarQ.com> Content-Type: text/plain; charset=us-ascii Organization: Pratt & Whitney Mime-Version: 1.0 Reply-To: diespammer@pwfl.com Newsgroups: comp.lang.ada Date: 1999-04-29T00:00:00+00:00 List-Id: Fraser Wilson wrote: > > Here's a question: has anyone ever used a modular type which was not > a power of 2, and lived to tell the tale? What was the context? > Reasonably often. I've found them useful as cycle counters or in creating some form of circular queue. Certainly not as frequently as one would, say, use the standard Integer, but often enough that I find it a convenience. I've seen a number of times in code something equivalent to: X := X + 1 ; if (X > Some_Max_Limit) then X := 0 ; end if ; A modular type of a non-power-of-2 makes this a natural thing because it is the compiler's problem to figure out if we've hit the wraparound point & it will likely do this as efficiently as possible. I think I've seen this most frequently in some form of bus communication where raw data is being buffered, buffers are being toggled or where data is being read and dropping stale data is "a good thing". But I also see it in code that deals with cyclic events - not all of which happen in powers of two and quite frequently you want the ability to "tune" the number of cycles by recompiling with new constants. MDC -- Marin David Condic Real Time & Embedded Systems, Propulsion Systems Analysis United Technologies, Pratt & Whitney, Large Military Engines M/S 731-95, P.O.B. 109600, West Palm Beach, FL, 33410-9600 ***To reply, remove "bogon" from the domain name.*** Visit my web page at: http://www.flipag.net/mcondic