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,747be3e35071507b,start X-Google-Attributes: gid103376,public From: Theodore Dennison Subject: Re: Calling C function with structure parameter from ADA Date: 1995/03/29 Message-ID: <3lbu1o$n3p@theopolis.orl.mmc.com>#1/1 X-Deja-AN: 100540715 references: to: cgw1@le.ac.uk content-type: text/plain; charset=iso-8859-1 organization: IPL InterNetNews site x-url: news:Pine.SGI.3.91.950328180834.25150D-100000@hawk mime-version: 1.0 newsgroups: comp.lang.ada Date: 1995-03-29T00:00:00+00:00 List-Id: C.G. Williams > A friend from China (Dr Kougen Zheng) asked me to post this request... > > Help Please!!! > Q: How can an ADA program call a C function with a structure as a parameter? > Any help will be greatly appreciated > > Please respond to: cgw1@le.ac.uk > (I will post a summary of any replies in a few days) > .. > typedef struct { > int x; > int y; > } Point; > > printa(pp) > Point pp; > > printf("\n coordinate = ( %d , %d )", pp.x, pp.y); > The problem here is that C passes the Point structure to printa by pushing the Point structure on the stack. C (even ANSI C) does not define what order the bytes of Point are pushed on the stack! That means there is no safe way to call printa directly from Ada. In addition to this, Ada does not define weather it pushes Point on the stack, or meerly the Address of Point. However your Ada compiler docs should either say how it passes parameters, or allow you to specify. So... Make sure that your Ada compiler is passing the ADDRESS of Point (not Point itself). Next do either of the following: 2) Change the C printa procedure to read: printa (pp) Point *pp; printf("\n coordinate = ( %d , %d )", pp->x, pp->y); 3) Create a third C routine: printainterface (pp) Point *pp; printa (*pp); and change you Ada program to call printainterface instead. T.E.D. (structured programming bigot)