comp.lang.ada
 help / color / mirror / Atom feed
* How to access this package written in C?
@ 2010-04-21 16:43 resander
  2010-04-21 17:39 ` Dmitry A. Kazakov
                   ` (2 more replies)
  0 siblings, 3 replies; 19+ messages in thread
From: resander @ 2010-04-21 16:43 UTC (permalink / raw)


I am working on software that manipulates SQL databases via a GUI. It
is written in C or C++ without classes and compiled on Linux. Would
also want it to run on Windows eventually. This software has
essentially one entry procedure:

  int guidb ( int appno , int recaddress );  // in C

which returns an outcome as an int, takes an int appno which specifies
application and an address of a record in recaddress. The latter is
used for passing the memory address of any recordtype variable and is
cast to a byte address inside guidb.

guidb uses appno to locate field-offsets and length of the recordtype
in tables built by initialisation functions for all recordtypes that
take part.

Typical use in C/C++:

typedef struct { int prodcode; float price; char descr [50]... }
PRODUCT;
typedef struct { bool bitesyou; int speciescode; char name[20] ... }
ANIMAL ;

void getproduct ( PRODUCT * pout , int * resultout )
   {
   *resultout = guidb ( 0 , (int)pout ) ;
   }

void addtozoo ( ANIMAL * a , int * resultout )
   {
   *resultout = guidb ( 1 , (int)a ) ;
   }

PRODUCT prod ;
ANIMAL addthis ;
int outcome ;

//  use as...

  getproduct ( &prod , &outcome );
  // get addthis animal data then
  addtozoo ( &addthis , &outcome );

All wrappers like getproduct and addtozoo are automatically generated
from other specs. That is easy in C by using fldoffset macro to get
field offsets and sizeof(rectypename) to get record length and a cast
that changes the interpretation of address to an int.

Desired use in Ada (same as above):

type PRODUCT is RECORD int prodcode; float price; char descr
[50]...END RECORD;

procedure getproduct ( p : out PRODUCT ; result : out int ) is
begin
   result = guidb ( 0 , address_of(p) how ??? ) ;
end

prod : PRODUCT;
outcome : int ;

  getproduct ( prod , outcome );


To be able to use the guidb with Ada I need to know how to:

 - get the memory address carried (how?) by the record formal
parameter
 - obtain field offsets for a record type
 - obtain length of a record object/variable

How to do this in in Ada? If it cannot be done, can the interface
above be changed to make it possible?

Ken




^ permalink raw reply	[flat|nested] 19+ messages in thread

end of thread, other threads:[~2010-05-03  8:12 UTC | newest]

Thread overview: 19+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-04-21 16:43 How to access this package written in C? resander
2010-04-21 17:39 ` Dmitry A. Kazakov
2010-04-22 20:12 ` Björn Persson
2010-04-22 21:12 ` Keith Thompson
2010-04-23 12:58   ` resander
2010-04-23 14:15     ` Dmitry A. Kazakov
2010-04-23 14:44     ` John B. Matthews
2010-04-23 15:39       ` John B. Matthews
2010-04-26 18:16     ` Robert A Duff
2010-04-26 19:57       ` Keith Thompson
2010-04-26 21:20         ` Maciej Sobczak
2010-04-27  6:52           ` Alex R. Mosteo
2010-04-27 22:29             ` Randy Brukardt
2010-05-03  8:12               ` Alex R. Mosteo
2010-04-27  0:20         ` Robert A Duff
2010-04-27  1:01           ` Keith Thompson
2010-04-27 16:07             ` Robert A Duff
2010-04-27 22:29               ` Randy Brukardt
2010-04-27  1:31           ` Randy Brukardt

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