comp.lang.ada
 help / color / mirror / Atom feed
* Interfacing to C non-void procedure with "out" parameters
@ 2000-01-14  0:00 Dr Steve Sangwine
  2000-01-14  0:00 ` Ted Dennison
                   ` (2 more replies)
  0 siblings, 3 replies; 8+ messages in thread
From: Dr Steve Sangwine @ 2000-01-14  0:00 UTC (permalink / 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





^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2000-01-18  0:00 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2000-01-14  0:00 Interfacing to C non-void procedure with "out" parameters Dr Steve Sangwine
2000-01-14  0:00 ` 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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox