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=-0.8 required=5.0 tests=BAYES_00,INVALID_DATE autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,23c28b14f995b7d4 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 1994-11-01 16:23:29 PST Path: nntp.gmd.de!xlink.net!sol.ctr.columbia.edu!howland.reston.ans.net!gatech!newsxfer.itd.umich.edu!caen!msuinfo!harbinger.cc.monash.edu.au!aggedor.rmit.EDU.AU!goanna.cs.rmit.oz.au!macdale.cs.rmit.edu.au!dale From: Dale Stanbrough Newsgroups: comp.lang.ada Subject: Re: Interfaces.C Date: 1 Nov 1994 22:45:34 GMT Organization: RMIT, Melbourne, Australia Distribution: world Message-ID: <396gee$knl@goanna.cs.rmit.oz.au> References: <395o3q$2j1@wynkyn.ecs.soton.ac.uk> NNTP-Posting-Host: macdale.cs.rmit.edu.au X-UserAgent: Version 1.1.3 X-XXMessage-ID: X-XXDate: Wed, 2 Nov 94 09:48:12 GMT Date: 1994-11-01T22:45:34+00:00 List-Id: Subject: Interfaces.C From: Ken Thomas, kst@ecs.soton.ac.uk Date: 1 Nov 1994 15:50:18 -0000 In article <395o3q$2j1@wynkyn.ecs.soton.ac.uk> Ken Thomas, kst@ecs.soton.ac.uk writes: >I am attempting to write an Ada9X interface for a C function >with specification > >void foo(int *a, int l) > >the aim being to pass an integer array to the C-function. What is the >correct usage of the package Interfaces.C and its children? > >Ken Thomas >University of Southampton >U.K. >kst@uk.ac.soton.ecs -- presuming l is the length of the array... type list is array(integer range <>) of interfaces.C.int; procedure foo(a:in out list) is procedure C_foo(a:in system'address; l:interfaces.c.int); pragma import(C, C_foo, "foo"); begin C_foo(a(a'first)'address, interfaces.c.int(a'length)); end; or... -- has the advantage of isolating the nasty C bits. type list is array(integer range <>) of some_integer_type; procedure foo(a:in out list) is procedure C_foo(a:in system'address; l:interfaces.c.int); pragma import(C, C_foo, "foo"); temp :array(a'range) of interfaces.c.int; begin for i in a'range loop temp(i) := interfaces.c.int(a(i)); end loop; C_foo(temp(temp'first)'address, interfaces.c.int(temp'length)); for i in temp'range loop a(i) := some_integer_type(temp(i)); end loop; end; Dale ------------------------------------------------------------- Dale Stanbrough, RMIT, Melbourne, Australia, dale@rmit.edu.au GNU Ada 94 (GNAT) => the best $0 you'll ever spend. Available for DOS, Linux, OS/2, Sun Sparc, Sun Solaris, ... Coming to a GNU supported platform near you soon...