comp.lang.ada
 help / color / mirror / Atom feed
From: kilgallen@eisner.decus.org (Larry Kilgallen)
Subject: Re: Ada to C interface
Date: 1997/01/24
Date: 1997-01-24T00:00:00+00:00	[thread overview]
Message-ID: <1997Jan24.071703.1@eisner> (raw)
In-Reply-To: 32E79A20@snoopy


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




      reply	other threads:[~1997-01-24  0:00 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1997-01-23  0:00 Ada to C interface Tim Armentrout
1997-01-24  0:00 ` Larry Kilgallen [this message]
replies disabled

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