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,2a34b7ad6c6a0774 X-Google-NewGroupId: yes X-Google-Attributes: gida07f3367d7,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news2.google.com!npeer02.iad.highwinds-media.com!news.highwinds-media.com!feed-me.highwinds-media.com!nntp.club.cc.cmu.edu!micro-heart-of-gold.mit.edu!bloom-beacon.mit.edu!newsswitch.lcs.mit.edu!nntp.TheWorld.com!not-for-mail From: Robert A Duff Newsgroups: comp.lang.ada Subject: Re: Efficiency of code generated by Ada compilers Date: Sun, 08 Aug 2010 16:51:37 -0400 Organization: The World Public Access UNIX, Brookline, MA Message-ID: References: <1jmwhfp.roo31ybayx2bN%csampson@inetworld.net> NNTP-Posting-Host: shell01.theworld.com Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: pcls6.std.com 1281300681 4821 192.74.137.71 (8 Aug 2010 20:51:21 GMT) X-Complaints-To: abuse@TheWorld.com NNTP-Posting-Date: Sun, 8 Aug 2010 20:51:21 +0000 (UTC) User-Agent: Gnus/5.1008 (Gnus v5.10.8) Emacs/21.3 (irix) Cancel-Lock: sha1:QS5jf3kUOsa6aFeaznwqn5BFvmc= Xref: g2news1.google.com comp.lang.ada:12969 Date: 2010-08-08T16:51:37-04:00 List-Id: csampson@inetworld.net (Charles H. Sampson) writes: > Robert A Duff wrote: > > I'm surprised, Bob. Are you saying that you signed integers in > preference to a modular type for a variable that cycles? Yes. Unless I'm forced to use modular for some other reason (e.g. I need one extra bit). >...I use > modular-typed variables and, if I've got my engineer's hat on, write > > I := I + 1; -- Modular variable. Wraps. You're not alone. Even Tucker has advocated using modular types for this sort of thing. But I think an explicit "mod N" is clearer than a comment. Variables that cycle are rare, so should be noted explicitly in the code. And, as Dmitry noted, modular types only work when the lower bound is 0. It's not unreasonable to have a circular buffer indexed by a range 1..N. See my point? Still "surprised"? > but I have to admit that in the heat of battle the comment might be > omitted. Even in that case, the variable name probably indicates that > wrapping should be expected. - Bob P.S. Can anybody recall the definition of "not" on modular types, when the modulus is not a power of 2, without looking it up? Hint: It makes no sense. The only feature that's worse than "modular types" is "modular types with a non-power-of-2 modulus". ;-)