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.3 required=5.0 tests=BAYES_00, REPLYTO_WITHOUT_TO_CC autolearn=no autolearn_force=no version=3.4.4 X-Google-Thread: 103376,ac6f6c30c45f808a X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news1.google.com!newsread.com!news-xfer.newsread.com!nntp.abs.net!news-FFM2.ecrc.net!newsfeed00.sul.t-online.de!newsmm00.sul.t-online.de!t-online.de!news.t-online.com!not-for-mail From: Martin Krischik Newsgroups: comp.lang.ada Subject: Re: Ada equivalent for C-pointer? Date: Sun, 16 Jan 2005 17:02:31 +0100 Organization: None Message-ID: <5149344.sr9q7XqTZ2@linux1.krischik.com> References: <41E7F653.2F899F47@alfred-hilscher.de> <7107744.J8aUxUzYtP@linux1.krischik.com> <41EA81CC.8090804@nowhere.fi> Reply-To: martin@krischik.com Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7Bit X-Trace: news.t-online.com 1105947344 02 5244 Z+hrr2TlNnQ+Pxo 050117 07:35:44 X-Complaints-To: usenet-abuse@t-online.de X-ID: TbjaywZDgeRiZKuDpm8uhkD-uvcH6nsGUOTCApncqYxxUYeAxEylQ+ User-Agent: KNode/0.8.0 Xref: g2news1.google.com comp.lang.ada:7861 Date: 2005-01-16T17:02:31+01:00 List-Id: Niklas Holsti wrote: > Martin Krischik wrote: >> Pascal Obry wrote: >> >> >>>Nick Roberts writes: >>> >>> >>>>For example, if there is a C function defined thus: >>>> >>>> int wibble(int *n); >>>> >>>>then in Ada you can declare: >>>> >>>> function Wibble (Number: in out Interfaces.C.int); >>>> pragma Import(C,Wibble,"wibble"); >>>> >>>>and it should work. (Obviously, you must link the C functions in >>>>somehow.) >>> >>>I don't think so. Here Number will be passed by value, no? And you also >>>need the returned value ;) >> >> >> No all out and in out parameter are passed as pointer when pragma >> Import(C is used - thats unless you use C_Pass_By_Copy. I have written >> quite a lot of code interfaceing with C. > > But according to LRM B.3(68), for an "in out" parameter of an > *elementary* type (as here) the pointer that is passed to the C function > is a pointer to a *temporary copy* of the parameter (here Number), not a > pointer to the parameter itself. This may not be what the C function > expects. Interesting. I have to think about that. Question is if the optimizer is allowed to remove the copy. > For example, it would not make sense for "wibble" to save the > pointer for later use. Well storing a pointer to a stack object is allways wrong. If you want to store a pointer to the object neither "in out" nor "anomymous access" is appropiate - a "pool access" should be used instead. And the Ada interface should reflect that - if only to document propper use. Martin -- mailto://krischik@users.sourceforge.net http://www.ada.krischik.com