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,ec21c3c7cdc7ff3e X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news3.google.com!news4.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!newscon06.news.prodigy.com!prodigy.net!newsfeed-00.mathworks.com!nntp.TheWorld.com!not-for-mail From: Robert A Duff Newsgroups: comp.lang.ada Subject: Re: private types Date: 18 Mar 2006 07:47:09 -0500 Organization: The World Public Access UNIX, Brookline, MA Message-ID: References: <1142279908.327131.230200@j52g2000cwj.googlegroups.com> NNTP-Posting-Host: shell01.theworld.com Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: pcls4.std.com 1142686029 17545 192.74.137.71 (18 Mar 2006 12:47:09 GMT) X-Complaints-To: abuse@TheWorld.com NNTP-Posting-Date: Sat, 18 Mar 2006 12:47:09 +0000 (UTC) User-Agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.2 Xref: g2news1.google.com comp.lang.ada:3429 Date: 2006-03-18T07:47:09-05:00 List-Id: "Randy Brukardt" writes: > It's not just testing. Ada 95 is very clear that an Ada compiler cannot > assume an object is in range unless it can prove it is initialized. This is not quite true. What the compiler can prove depends on the compiler's code generation strategy. Example: type Index is range 1..10; type A is array(Index) of Character; X: Index; -- not initialized here procedure P(Y: Index) is begin ... end P; ... -- (*) might initialize X here P(X); Suppose the compiler cannot prove that the code marked "-- (*)" will initialize X. The compiler has a choice: It can do a range check at the call to P, and then assume inside the body of P that Y is in range (even though the value _might_ have come from an uninitialized variable). Or, the compiler can avoid the range check on the call to P, in which case it cannot assume that Y is in range. > So I recommend initalizing everything (or assigning it immediately after the > begin) that could be significant to performance. That also depends on the compiler. Many compilers can prove that a variable is initialized here: begin if ... then A := 3; else A := 4; end if; ... -- Here, we can presume A is in range. Adding "A := 0;" between "begin" and "if" would be overkill for such compilers. - Bob