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.7 required=5.0 tests=BAYES_00,INVALID_DATE, MSGID_SHORT,REPLYTO_WITHOUT_TO_CC autolearn=no autolearn_force=no version=3.4.4 Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!uunet!mcsun!ukc!cam-cl!cet1 From: cet1@cl.cam.ac.uk (C.E. Thompson) Newsgroups: comp.lang.ada Subject: Re: how to do this in Ada? Message-ID: <1811@gannet.cl.cam.ac.uk> Date: 19 Mar 90 17:11:39 GMT References: <256@avocado.uucp> Sender: news@cl.cam.ac.uk Reply-To: cet1@cl.cam.ac.uk (C.E. Thompson) Organization: U of Cambridge Comp Lab, UK List-Id: In article <256@avocado.uucp> garym@sugar.hackercorp.com writes: > ... >The C compiler will probably generate a table jump. But before it can index >into the table it must make sure that the index is within the range 0..2, that >takes 2 compares. ... A common fallacy. With any machine instruction set that you care to name, you will find that you can test a value for being in the range a..b with an add/subtract and one compare (and subsequent conditional branch): usually a subtract of 'a' and an unsigned comparison with 'b-a'. If a is zero, as here, the subtract disappears as well. Of course, this applies to the Ada range test as well. Chris Thompson JANET: cet1@uk.ac.cam.phx Internet: cet1%phx.cam.ac.uk@nsfnet-relay.ac.uk