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.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,31c63f07e48d5471 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2003-02-18 08:49:16 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!news.uchicago.edu!newsswitch.lcs.mit.edu!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!peernews-us.colt.net!newsfeed.news2me.com!newsfeed2.earthlink.net!newsfeed.earthlink.net!stamper.news.pas.earthlink.net!newsread1.prod.itd.earthlink.net.POSTED!not-for-mail Message-ID: <3E5263FB.6060901@acm.org> From: Jeffrey Carter User-Agent: Mozilla/5.0 (Windows; U; Win98; en-US; rv:1.0.0) Gecko/20020530 X-Accept-Language: en-us, en MIME-Version: 1.0 Newsgroups: comp.lang.ada Subject: Re: Ada to 'C' parameter passing problem References: Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit Date: Tue, 18 Feb 2003 16:47:41 GMT NNTP-Posting-Host: 63.184.9.64 X-Complaints-To: abuse@earthlink.net X-Trace: newsread1.prod.itd.earthlink.net 1045586861 63.184.9.64 (Tue, 18 Feb 2003 08:47:41 PST) NNTP-Posting-Date: Tue, 18 Feb 2003 08:47:41 PST Organization: EarthLink Inc. -- http://www.EarthLink.net Xref: archiver1.google.com comp.lang.ada:34202 Date: 2003-02-18T16:47:41+00:00 List-Id: Patrick wrote: > 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. Compare the values of System.Max_Int on the Solaris compiler and GNAT. GNAT supports 64-bit integers on all platforms, while it's likely the compiler used on Solaris only supports 32-bit integers. This might explain what you're seeing. There's no need for all this complication in the interface. You could declare the procedure as taking System.Address for its parameters in Ada, and simply pass the addresses without the conversions. This would be a simple modification to get things working. A C pointer is generally an address, and Ada and C compilers for the same platform generally use the same representation for an address. If you want to put more effort into it, you could check out Annex B and learn how things are passed to a C subprogram, and get some type checking into the call as well. -- Jeff Carter "The time has come to act, and act fast. I'm leaving." Blazing Saddles