comp.lang.ada
 help / color / mirror / Atom feed
From: Theodore Dennison <dennison@escmail.orl.mmc.com>
To: cgw1@le.ac.uk
Subject: Re: Calling C function with structure parameter from ADA
Date: 1995/03/29
Date: 1995-03-29T00:00:00+00:00	[thread overview]
Message-ID: <3lbu1o$n3p@theopolis.orl.mmc.com> (raw)
In-Reply-To: Pine.SGI.3.91.950328180834.25150D-100000@hawk

C.G. Williams<cgw1@le.ac.uk> 
> 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)





  reply	other threads:[~1995-03-29  0:00 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1995-03-28 17:22 Calling C function with structure parameter from ADA C.G. Williams
1995-03-29  0:00 ` Theodore Dennison [this message]
1995-04-06  0:00   ` Robert Dewar
1995-04-07  0:00     ` Chris Warack <sys mgr>
1995-04-07  0:00       ` Robert Dewar
     [not found]     ` <D6pwGs.8wE@thomsoft.com>
1995-04-19  0:00       ` Fergus Henderson
replies disabled

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