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,e5a3abec221df39 X-Google-Attributes: gid103376,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!postnews.google.com!w24g2000prd.googlegroups.com!not-for-mail From: Adam Beneschan Newsgroups: comp.lang.ada Subject: Re: Possible compiler bug with this simple program Date: Thu, 28 Aug 2008 08:54:15 -0700 (PDT) Organization: http://groups.google.com Message-ID: References: <1edc3682-855f-405b-8348-72b423377b1a@i20g2000prf.googlegroups.com> <48b65b3b$0$25384$4f793bc4@news.tdc.fi> NNTP-Posting-Host: 66.126.103.122 Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-Trace: posting.google.com 1219938855 8974 127.0.0.1 (28 Aug 2008 15:54:15 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Thu, 28 Aug 2008 15:54:15 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: w24g2000prd.googlegroups.com; posting-host=66.126.103.122; posting-account=duW0ogkAAABjRdnxgLGXDfna0Gc6XqmQ User-Agent: G2/1.0 X-HTTP-UserAgent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.7.12) Gecko/20050922 Fedora/1.7.12-1.3.1,gzip(gfe),gzip(gfe) Xref: g2news1.google.com comp.lang.ada:1810 Date: 2008-08-28T08:54:15-07:00 List-Id: On Aug 28, 1:03 am, Niklas Holsti wrote: > In fact, when an Ada subprogram has an unconstrained array > parameter with Convention C, it seems to me that the subprogram's > body cannot make any use of individual elements of the array, > because it doesn't know the index range, so the compiler should > reject any indexing of such an array parameter, as well as any > attempt to pass it on as a Convention Ada parameter. Yes, good point. For an unconstrained array parameter like X, the compiler doesn't need to know what X'Last is in order to access elements of the array---but it does need to know X'First. (X'Last is needed for range checking but not for actually accessing elements.) If you're using strictly Ada, with no Convention parameters or anything, then when mapform19 is called, the caller somehow has to make X'First and X'Last available to the routine, and then when X(I) is accessed, the generated code must compute I - X'First, multiply that by the element size, and add the result to the address of X's data. When mapform19 is called from a C routine, nothing will be passed in for X'First, but mapform19 will still try to subtract something from I, and what value it will subtract is quite random--- could be zero, could be some other garbage value. I agree that the compiler should have rejected this. But it might work to declare Real_Vector as a constrained array: type Real_Vector is array (0 .. Integer'Last) of Long_Float; Now the compiler will know that X'First is 0 and, hopefully, behave correctly. -- Adam