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.3 required=5.0 tests=BAYES_00, REPLYTO_WITHOUT_TO_CC autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,6a67711028c980fb X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2003-07-04 08:43:14 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!newsfeed00.sul.t-online.de!newsmm00.sul.t-online.com!t-online.de!news.t-online.com!not-for-mail From: Martin Krischik Newsgroups: comp.lang.ada Subject: Re: range checking Date: Fri, 04 Jul 2003 06:52:59 +0200 Organization: AdaCL Message-ID: <1124504.87IONMPbAv@linux1.krischik.com> References: Reply-To: krischik@users.sourceforge.net Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7Bit X-Trace: news.t-online.com 1057333310 06 21859 yUVlVjFVSUAfjq 030704 15:41:50 X-Complaints-To: usenet-abuse@t-online.de X-ID: S3UQxsZDweI21lsrPqerYvjIcktG1srjqnSwE-HuveoaUbeXyy56ER User-Agent: KNode/0.7.2 Xref: archiver1.google.com comp.lang.ada:40062 Date: 2003-07-04T06:52:59+02:00 List-Id: Dinakar Dhurjati wrote: > Hi, > > I am a researcher in compilers/security. > > I am looking to adapt Ada's subrange idea for eliminating some array > bounds checks for a different language. I am curious as to how the thing > works in common implementations. Any pointers welcome. > > Specifically > > (1) Are there any compilers which try to infer the subranges themselves > Or the subranges have to be given by the programmer ? The compiler can deduct the range on assignment: x : String (0 .. 10); y : String := x; Once y has x assigned to it the range is frozen and cannot be changed. The size does not need to be known at compile time: procedure x (Size : Integer) is x : String (0 .. Size); begin null; end x; > (2) If a variable is declared is of type some subrange, then every > assignment to that variable needs to be checked for correctness -- i.e. if > the assigned value is with in the subrange, right ? Are these checks done > statically or at runtime ? Are there any compilers which try to reduce the > amount of runtime checks that need to be done ? The optimizer usualy analyzes the assignment and removed unneded checks. So in x := x + 1; only the upper bound need to be checked. The optimizer usualy will also make a static checks and issue a warning. i.E.: x : Interger := Integer'Last; x := x + 1; might raise a warning at compile time. However the language standart does not enforce the existance of an optimizer. With Regards Martin -- mailto://krischik@users.sourceforge.net http://www.ada.krischik.com