From: S.J.Sangwine@Reading.ac.uk (Dr Steve Sangwine)
Subject: Interfacing to C non-void procedure with "out" parameters
Date: 2000/01/14
Date: 2000-01-14T00:00:00+00:00 [thread overview]
Message-ID: <387f1c30.12554815@news.rdg.ac.uk> (raw)
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
next reply other threads:[~2000-01-14 0:00 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2000-01-14 0:00 Dr Steve Sangwine [this message]
2000-01-14 0:00 ` Interfacing to C non-void procedure with "out" parameters Ted Dennison
2000-01-14 0:00 ` Jeff Carter
2000-01-14 0:00 ` Ted Dennison
2000-01-15 0:00 ` Jeff Carter
2000-01-14 0:00 ` Alain Le Guennec
2000-01-17 0:00 ` Matthew Heaney
2000-01-18 0:00 ` Dr Steve Sangwine
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox