comp.lang.ada
 help / color / mirror / Atom feed
From: Pat.Donahue@msfc.nasa.gov (Patrick)
Subject: Ada to 'C' parameter passing problem
Date: 18 Feb 2003 07:39:19 -0800
Date: 2003-02-18T15:39:19+00:00	[thread overview]
Message-ID: <ea3b54bb.0302180739.3cb6c159@posting.google.com> (raw)

I am using GNAT Ada on Linux.  I am trying to port from a Sun
(Solaris) implementation.  I didn't write the Ada or 'C' myself, but
am trying to make it work on Linux.  The Ada code passes five
parameters to the 'C' code.  It is trying to pass the address in each
case so that the 'C' can pass back status in the variables
(parameters).  The below Ada code (in tls.ads) contains the definition
of the function "to_c_pointer" to convert the Ada address to a
"c_pointer":
   type us1 is range 0..SYSTEM.MAX_INT;
   subtype unsigned_long is us1;
   subtype c_pointer is unsigned_long;
   -- convert ada address into a value that can be assigned
   -- to a c pointer.  The following is an example of a call to
   -- to_c_pointer: TLS.to_c_pointer(i'ADDRESS)
   function to_c_pointer is new 
      unchecked_conversion(SYSTEM.address, c_pointer);
   pragma inline(to_c_pointer);

Here is what the Ada call to 'C' looks like:
DMC_Initialize_Database_Configuration_C(
                    TLS.to_c_pointer(Configuration_Id_In'ADDRESS),
                    TLS.to_c_pointer(Configuration_Id_Len'ADDRESS),
                    TLS.to_c_pointer(Initialization_Status_Ind'ADDRESS),
                    TLS.to_c_pointer(Init_Failure_Text_In'ADDRESS),
                    TLS.to_c_pointer(Init_Failure_Text_Len'ADDRESS));

Here is what the 'C' funtion definition looks like:
DMC_Initialize_Database_Configuration_C(
                    char *Configuration_Id,
                    int *Configuration_Id_Len,
                    int *Initialization_Status,
                    char *Init_Failure_Text,
                    int *Init_Failure_Text_Len)
{

As I said, there are five parameters.  This worked fine under Solaris
(Spark compiler for Ada), but under Linux the address of the 2nd and
4th parameters ends up being zero on the 'C' side (we can tell this
with a debugger).  Using the debugger, it looks like the first
parameter on the Ada side is being passed into the first parameter on
the 'C' side.  The second parameter on the Ada side shows up on the
'C' side as the third parameter.  The third parameter on the Ada side
shows up on the 'C' side as the fifth parameter.  So, at least on the
surface, it looks as if the size of the parameter on the Ada side is
twice the size of the parameter on the 'C' and it is filling in with
zero.

Have you run into anything similar that would enable you to help me
solve this problem?

Thanks for any help you can give me,



             reply	other threads:[~2003-02-18 15:39 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-02-18 15:39 Patrick [this message]
2003-02-18 16:47 ` Ada to 'C' parameter passing problem Jeffrey Carter
2003-02-18 19:50 ` Rod Chapman
2003-02-20  2:36   ` Matthew Heaney
2003-02-20  9:18     ` Rod Chapman
2003-02-20  9:43       ` Dmitry A. Kazakov
2003-02-20 22:05       ` Simon Wright
2003-02-21  9:53         ` Stuart Palin
2003-02-21 17:39           ` Jeffrey Carter
2003-02-21 18:12           ` Warren W. Gay VE3WWG
2003-02-21 20:25           ` Randy Brukardt
2003-02-24 23:53       ` Matthew Heaney
2003-02-25 17:21         ` Rod Chapman
  -- strict thread matches above, loose matches on Subject: below --
2003-02-21 16:52 Lionel.DRAGHI
replies disabled

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