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,7140daf195c59fcf X-Google-Attributes: gid103376,public From: kilgallen@eisner.decus.org (Larry Kilgallen) Subject: Re: Ada to C interface Date: 1997/01/24 Message-ID: <1997Jan24.071703.1@eisner>#1/1 X-Deja-AN: 211924373 x-nntp-posting-host: eisner.decus.org references: <32E79A20@snoopy> x-nntp-posting-user: KILGALLEN x-trace: 854108230/8535 organization: LJK Software newsgroups: comp.lang.ada Date: 1997-01-24T00:00:00+00:00 List-Id: In article <32E79A20@snoopy>, Tim Armentrout 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