comp.lang.ada
 help / color / mirror / Atom feed
* Ada to C interface
@ 1997-01-23  0:00 Tim Armentrout
  1997-01-24  0:00 ` Larry Kilgallen
  0 siblings, 1 reply; 2+ messages in thread
From: Tim Armentrout @ 1997-01-23  0:00 UTC (permalink / raw)



I'm trying to interface a C program to an Ada program, and have run into
difficulty.  The problem is this: I have an Ada record defined.  I have a
C procedure that needs to operate on this record.  However, the Ada
program must operate on it also.  The C procedure involves some extensive
low level bit manipulation that runs faster than equivalent Ada code.  I
would like to take advantage of the increased speed by calling the C
procedure directly from my Ada program.  However, how do I export the Ada
record structure so that my C compiler can resolve references to it,
without doing a pragma in-line ?  Please help...

 -- Tim (tarmen@dahlgren.tsc.com)




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

* Re: Ada to C interface
  1997-01-23  0:00 Ada to C interface Tim Armentrout
@ 1997-01-24  0:00 ` Larry Kilgallen
  0 siblings, 0 replies; 2+ messages in thread
From: Larry Kilgallen @ 1997-01-24  0:00 UTC (permalink / raw)



In article <32E79A20@snoopy>, Tim Armentrout <tarmen@DAHLGREN.TSC.COM> writes:
> I'm trying to interface a C program to an Ada program, and have run into
> difficulty.  The problem is this: I have an Ada record defined.  I have a
> C procedure that needs to operate on this record.  However, the Ada
> program must operate on it also.  The C procedure involves some extensive
> low level bit manipulation that runs faster than equivalent Ada code.  I
> would like to take advantage of the increased speed by calling the C
> procedure directly from my Ada program.  However, how do I export the Ada
> record structure so that my C compiler can resolve references to it,
> without doing a pragma in-line ?  Please help...

The Representation Clause capability of Ada lets you set the precise
layout in memory of your record from Ada83 forward.  Capabilities you
have for this in C will depend on what has been provided by the vendor
of your C compiler.  You can thus use these two mechanisms to "meet
in the middle" or at least "meet all the way over on the C side".

As a user of Ada, I would prefer you pursue the issue of the
"low level bit manipulation that runs faster" in C, since someday
I might have to use the Ada compiler you are using (whatever it is)
and if there is a performance problem it should be addressed. It
seems to me there are adequate methods in Ada to specify a bit
pattern more fully than in C, so that Ada should be no less
efficient at providing the same level of service, safety, etc.

But if you really have reason to care about any of this you should
probably tailor your record definition to match the fussiest rules
associated with your hardware to really get maximum speed.  What
look like equivalent memory accesses of 32-bit quantities, for
example, can have considerable performance differences depending
on whether they are 64-bit aligned on certain machines due to the
way that memory access busses are constructed.

Larry Kilgallen




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

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

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1997-01-23  0:00 Ada to C interface Tim Armentrout
1997-01-24  0:00 ` Larry Kilgallen

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