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.9 required=5.0 tests=BAYES_00,FORGED_GMAIL_RCVD, FREEMAIL_FROM autolearn=no autolearn_force=no version=3.4.4 X-Google-Thread: 103376,5a84d5077c54a29d X-Google-Attributes: gid103376,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!postnews.google.com!z32g2000prh.googlegroups.com!not-for-mail From: Adrian Hoe Newsgroups: comp.lang.ada Subject: Re: Ada array vs C pointer (call by reference) Date: Thu, 26 Jun 2008 18:42:12 -0700 (PDT) Organization: http://groups.google.com Message-ID: <22f8f291-8244-4380-89b3-49b1c2c5f38f@z32g2000prh.googlegroups.com> References: NNTP-Posting-Host: 60.53.234.99 Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-Trace: posting.google.com 1214530932 19925 127.0.0.1 (27 Jun 2008 01:42:12 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Fri, 27 Jun 2008 01:42:12 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: z32g2000prh.googlegroups.com; posting-host=60.53.234.99; posting-account=coq9PAkAAAB2Xx46RZLFJw5dY9DVXW4- User-Agent: G2/1.0 X-HTTP-UserAgent: Mozilla/5.0 (Macintosh; U; Intel Mac OS X; en-US; rv:1.8.1.14) Gecko/20080404 Firefox/2.0.0.14,gzip(gfe),gzip(gfe) Xref: g2news1.google.com comp.lang.ada:900 Date: 2008-06-26T18:42:12-07:00 List-Id: On Jun 27, 9:39 am, Adrian Hoe wrote: > Hi, > > I have a C library function which takes a float * as a parameter. The > function is as below: > > int pwmRead (int pwmCount, float * data); > > where data is an array of float which size is determined by pwmCount. > > In Ada, I have: > > PWM_Count : Integer := No_Of_Components_Intended; > PWM_Data : array (1 .. PWM_Count) of Float; > > My concern is how safe to pass an Ada array to a C function as a > pointer (call by reference)? I presume Ada will allocate contiguous > memory for array, but what if it does not? How can we establish a > deterministic allocation and to make sure float * is accessed > contiguously? Is there any "safe" way to do this? > > Thanks. > -- > Adrian Hoehttp://adrianhoe.com Sorry, PWM_Count should be declared as constant: PWM_Count : constant := No_Of_Components_Intended;