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,XPRIO autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,8a3d369650eccae6,start X-Google-Attributes: gid103376,public From: "Deepak Haste" Subject: Interface with C Date: 1999/05/20 Message-ID: <7i1n9t$6fs@beast.connix.com>#1/1 X-Deja-AN: 480235679 X-Priority: 3 X-MimeOLE: Produced By Microsoft MimeOLE V5.00.2314.1300 Organization: Connix Internet X-MSMail-Priority: Normal Newsgroups: comp.lang.ada Date: 1999-05-20T00:00:00+00:00 List-Id: Hello, I am implementing an ADA routine that interfaces with a Win32 C-library on an NT. I am trying to import an array into an ADA procedure from a C -function call. The C function looks like this > DllImport int GetKnownBadComponents_RT(int **bad_components, ...); A call to this function would give us the address of the array. **************************************************************************** *** The corresponding ADA binding looks like this : > type components is array(Integer range <>) of Integer; ------------------------------------------------ > pragma convention(C,components); ------------------------------------------------ > type components_ptr is access components; > function GetKnownBadComponents_RT(bad_components_ptr : in components_ptr; ..) return Integer; - - function prototype **************************************************************************** * While calling this function from an ada procedure I do: > badcomponents_ptr : components_ptr := new components(0 .. 9); - - initialized to point to a 10 component array > ret_code := GetKnownBadComponents_RT(badcomponents_ptr,...); - - the actual function call > for Item in badcomponents_ptr.all'range loop > Put(Integer'Image(badcomponents_ptr.all(Item))); > end loop; - - display array elements **************************************************************************** * Now, I know that the C function does not pass array of size greater than 5. Also, the inclusion/exclusion of the pragma convention makes it behave differently. When pragma is excluded, the procedure gives constraint error at the function call. When included, I get the first element correctly. However the display loop goes infinite giving out the rest as garbage. Any suggestions will be greatly appreciated. Thanks, Deepak Haste.