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-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,139d9b90ab37c0e5 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2001-11-01 09:54:16 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!jfk3-feed1.news.digex.net!dca6-feed2.news.digex.net!intermedia!newsfeed1.cidera.com!Cidera!cyclone1.gnilink.net!washdc3-snf1!washdc3-snh1.gtei.net!cambridge1-snf1.gtei.net!news.gtei.net!inmet!not-for-mail From: Tucker Taft Newsgroups: comp.lang.ada Subject: Re: When to do a constraint check and not ?? Date: Thu, 01 Nov 2001 12:54:14 -0500 Organization: AverCom Corp, a Titan company Message-ID: <3BE18C46.1AB713B4@avercom.net> References: <3BD91EF8.EEB7EDBA@systems.saab.se> NNTP-Posting-Host: 192.168.24.34 Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Trace: inmet2.burl.averstar.com 1004637249 24902 192.168.24.34 (1 Nov 2001 17:54:09 GMT) X-Complaints-To: usenet@inmet2.burl.averstar.com NNTP-Posting-Date: 1 Nov 2001 17:54:09 GMT X-Mailer: Mozilla 4.75 [en] (X11; U; SunOS 5.7 sun4u) X-Accept-Language: en Xref: archiver1.google.com comp.lang.ada:15559 Date: 2001-11-01T17:54:09+00:00 List-Id: Per Sandberg wrote: > > Assume the folowing code: > > procedue bla is > b : boolean; --< B may contain any bit pattern at this point. > > procedure test( p : in out boolean ) is > begin > b := false; I presume you meant to write: "p := false;" here. > end test; > > begin > test(b); --<< Is the compiler allowed to insert a constraint check on b > here ?? Yes, it may perform a constraint check here. In Ada 95, referencing an uninitialized variable is a "bounded error" (whereas in Ada 83 it was "erroneous"). This typically means that an Ada 95 compiler won't "believe" the subtype declaration of an object if it hasn't been initialized. Hence, it will need to check its value against the bounds of the subtype before it assigns it to an object that it *does* believe is in range. Certainly all compilers will want to believe that "in" and "in out" parameters are in range, so the (implicit) assignment from b to the formal parameter p when the function is called will need to ensure the value is in range. If it happens to have "stack junk" in it which puts it outside the typical 0..1 range used for booleans, then you will get a constraint_error raised here. So unless a compiler otherwise ensures that "b" is in range, it will want to perform a constraint check when it is passed to "test." As others have suggested, if you don't want a constraint check there, either initialize b, or make "p" into an "out" parameter rather than "in out". > end; > > Is the answer that it is up to the wendor. > I did not get any clues from the LRM. It is up to the vendor in some sense, but the fact that referencing an uninitialized variable is only a "bounded error" makes it quite likely that a check will be performed at this point to avoid having an uninitialized variable "poison" all IN and IN OUT parameters. > > /Per Sandberg. -- -Tucker Taft stt@avercom.net http://www.avercom.net Chief Technology Officer, AverCom Corporation (A Titan Company) Bedford, MA USA (AverCom was formerly the Commercial Division of AverStar: http://www.averstar.com/~stt)