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.3 required=5.0 tests=BAYES_00,INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,1726119712bbda0d,start X-Google-Attributes: gid103376,public From: S.J.Sangwine@Reading.ac.uk (Dr Steve Sangwine) Subject: Interfacing to C non-void procedure with "out" parameters Date: 2000/01/14 Message-ID: <387f1c30.12554815@news.rdg.ac.uk>#1/1 X-Deja-AN: 572547203 Organization: University of Reading Newsgroups: comp.lang.ada Date: 2000-01-14T00:00:00+00:00 List-Id: Can anyone shed light on the issue of interfacing between Ada95 and C where there is a C procedure (non-void) which returns a result *and* modifies some of its parameters? The LRM, Appendix B doesn't say anything about this, and neither does the Ada95 Rationale as far as I can see. I have a C procedure, for which I wanted to write an Ada95 spec, and import the C object code using pragma Import. Since the C procedure has a return result, I need an Ada function (or do I?). An Ada function must have parameters of mode 'in', implicitly or explicity, yet the C procedure will modify one or more of its parameters. To be safe, I wrote a wrapper procedure in C which had an extra parameter, and called this from Ada. The wrapper procedure called the real C procedure and returned the return result of the real C procedure in the extra parameter. That way the Ada spec can be a procedure and everything is watertight, but it is a nuisance to have this extra, trivial C wrapper procedure in between. Would it work to allow the C procedure to modify a parameter that the Ada code thinks is read-only (i.e. 'in'), or should I play safe as described above. (By 'work', I mean work portably, not work when compiled with a specific compiler.) Since C programmers routinely confuse the concepts of procedure and function (rant ....) this issue arises with almost any C code that one wants to interface to Ada. Dr Steve Sangwine Division of Electronic Engineering The University of Reading, UK http://www.elec.rdg.ac.uk/sjs.html