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!p39g2000prm.googlegroups.com!not-for-mail From: Adrian Hoe Newsgroups: comp.lang.ada Subject: Re: Ada array vs C pointer (call by reference) Date: Fri, 27 Jun 2008 18:15:10 -0700 (PDT) Organization: http://groups.google.com Message-ID: <5d649522-50be-4aa5-9dce-cd1daa2bcd0d@p39g2000prm.googlegroups.com> References: <3de9k.228623$yE1.227772@attbi_s21> 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 1214615710 1397 127.0.0.1 (28 Jun 2008 01:15:10 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Sat, 28 Jun 2008 01:15:10 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: p39g2000prm.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:930 Date: 2008-06-27T18:15:10-07:00 List-Id: On Jun 28, 6:54 am, "Jeffrey R. Carter" wrote: > Adrian Hoe wrote: > > > Can I use Float instead of Interfaces.C.C_Float? > > You can use anything you want: Boolean, Duration, a task type, ... > > But if you want to be sure it will work, you'll use Interfaces.C.C_Float. > > > Why use Interfaces.C.Int, Interfaces.C.C_Float since they are all new > > declaration of Ada types. > > > I know it is for readability and maintainability but the question is > > logical as the declaration in Interfaces.C is just merely creating a > > new Ada type with a new name, unless there is pragma Convention > > statement after every such declaration in Interfaces.C. > > I suggest you read ARM B.3. There you'll find, "Each of the types declared in > Interfaces.C is C-compatible." > > > Wouldn't it be better to write as such? > > > type C_Data is array (Positive range <>) of Float; > > pragma Convention (C, C_Data); > > Not if you want to be sure it will work. > > > Is PWM_Data passed as pointer to pwmRead? > > B.3 also contains, "An Ada parameter of an array type with component type T, of > any mode, is passed as a t* argument to a C function, where t is the C type > corresponding to the Ada type T." Ok. Ada somewhat guarantees a safe environment of its own. The ultimate concern is how Ada (or we) can guarantee a safe interfacing to C? Like those previous posts in this thread (by Maciej, Keith, et al), it depends on compiler implementation. The question is, the C library (which I am interfacing with) is compiled by unknown C compiler with unknown switches and the author cannot be contacted. The only documentation I have is the C header file. Can Ada safe implementation guarantee a safe interface in this case? Or rather, how Ada can guarantee a safe interface? This does not limit to float * but can be anything else. The reason I/ we ask this (stupid) question is that I want to eliminate undesired results because the results returned will be difficult to trace/prove for correctness. -- Adrian Hoe http://adrianhoe.com