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,c9b7709f7cadc963 X-Google-Attributes: gid103376,public From: Ken Garlington Subject: Re: Beware: Rep spec on an enumeration type clause Date: 1997/12/12 Message-ID: <3491E444.679E@nospam.flash.net>#1/1 X-Deja-AN: 297715857 References: <34911237.81B700D6@iei.pi.cnr.it> <34912418.13716044@news.geccs.gecm.com> Reply-To: Ken.Garlington@nospam.computer.org Organization: Flashnet Communications, http://www.flash.net Newsgroups: comp.lang.ada Date: 1997-12-12T00:00:00+00:00 List-Id: Brian Orpin wrote: > In 83 I would have simply checked to see if it was valid by > > Valid := I in T'First .. T'Last; > > Certainly on the Tartan Compiler for C40 this detects any invalid (not > represented) values of T. Be careful with this! Consider the following example (not compiled, so forgive any minor errors): type IO_Value is range 0 .. 15; for IO_Value'Size use 16; Raw_Value : IO_Value; Raw_IO.Read ( Raw_Value ); if Raw_Value not in IO_Value'Range then else ... end if; If Raw_IO.Read returns a value out of range 0 .. 15, the check is NOT GUARANTEED TO WORK. In particular, the TI/Tartan compiler for the MIL-STD-1750 (among others) will delete the check under almost all optimization levels (a fact I learned from painful personal experience), since Raw_Value is "known" to be in the range of its type upon return from the Read call. This is at least one of the reasons why 'Valid was introduced in the first place. > > -- > Brian Orpin (These thoughts are my own ......... for once!) > brian.orpin@gecm(dot)com or BrianOrpin@Bigfoot.com > http://www.borpin.demon.co.uk/ **Anti-spam reply-to**