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,bd45e29f9dafca87 X-Google-Attributes: gid103376,public From: Jeff Carter Subject: Re: bitwise comparators Date: 2000/02/05 Message-ID: <389C57B1.CD092E4D@earthlink.net>#1/1 X-Deja-AN: 581994919 Content-Transfer-Encoding: 7bit References: <3880D375.7E363123@hotmail.com> <38829638.0@news.pacifier.com> <3882FC1C.2BA8C959@hotmail.com> <389C4F0D.E5541B98@earthlink.net> X-Accept-Language: en Content-Type: text/plain; charset=us-ascii X-ELN-Date: Sat Feb 5 11:03:57 2000 X-Complaints-To: abuse@earthlink.net X-Trace: newsread2.prod.itd.earthlink.net 949777437 63.11.144.28 (Sat, 05 Feb 2000 11:03:57 PST) Organization: EarthLink Network, Inc. MIME-Version: 1.0 Reply-To: jrcarter@acm.org NNTP-Posting-Date: Sat, 05 Feb 2000 11:03:57 PST Newsgroups: comp.lang.ada Date: 2000-02-05T00:00:00+00:00 List-Id: Ashley Deas Eachus wrote: > Back to the original topic, I would probably use an array of Booleans as > the best representation of the original problem: > > type Register is array(1..32) of Boolean; > for Register'size use 32; > Some_Register: Register; > for Some_Register'Address use ...; > pragma Volitile(Some_Register); > constant Low_Order_Bit := ...; It's scary when Robert Eachus writes something like this. Can I assume you meant Low_Order_Bit : constant Positive := ...; ? Here we have my problem with using an array of Booleans: This code is not portable. On some machines Some_Register (1) is the LSB, on others, Some_Register (32). When you move it, you have to remember to make sure that this index is correct; it's very easy to forget that check, and the code will still compile and run. The resulting error may be intermittent, and finding it may be difficult. > .... > loop > -- setup code > exit when Some_Register(Low_Order_Bit); > -- functional code > end loop; > > or if you prefer: > > -- setup code > while not Some_Register(Low_Order_Bit) > loop > -- functional code > -- setup code > end loop; > > As you can see, the exit when version is better when there is significant > setup to be done for the test--the traditional loop and a half, and the while loop > is cleaner if there is no setup required. The "exit when" version is cleaner in both cases, because it uses positive logic, which has been demonstrated to be easier to understand (at least by us mere mortals :). -- Jeff Carter "Hello! Smelly English K...niggets." Monty Python & the Holy Grail