comp.lang.ada
 help / color / mirror / Atom feed
From: mheaney@on2.com (Matthew Heaney)
Subject: Re: Importing C structs?
Date: 31 Jul 2003 10:34:56 -0700
Date: 2003-07-31T17:34:57+00:00	[thread overview]
Message-ID: <1ec946d1.0307310934.223e1c71@posting.google.com> (raw)
In-Reply-To: pan.2003.07.31.07.52.36.94842.845@nospam.net

Freejack <freejack@nospam.net> wrote in message news:<pan.2003.07.31.07.52.36.94842.845@nospam.net>...
> On Thu, 31 Jul 2003 01:35:57 -0400, Matthew Heaney wrote:
> 
> > The type DBTYPE is a bit of a mystery at this point, since structs
> > aren't typically passed by value in C.  Perhaps DBTYPE is really a
> > pointer?
> 
> The header file declares it thusly....
> 
> /*******************************************************
>  * Access methods.
>  *******************************************************/
> /*
>  * !!!
>  * Changes here must be reflected in java/src/com/sleepycat/db/Db.java.
>  */
> 	typedef enum {
> 	DB_BTREE=1,
> 	DB_HASH,
> 	DB_RECNO,
> 	DB_QUEUE,
> 	DB_UNKNOWN			/* Figure it out on open. */
> 	} DBTYPE;
>  
> So I'm assuming I could just use an Ada enumerated type. (It compiles when I
> do this, but it fails at runtime.)

You'll need to use a rep clause to specify that the enumeration
literals start with value 1.  You'll also need to specify convention C
for the enumeration type.

type DBTYPE is (DB_BTREE, DB_HASH, ...);
pragma Convention (C, DBTYPE);
for DBTYPE use (DB_TYPE => 1);  --need others?

Alternatively, you could just use a C int type:

type DBTYPE is new C.int;

DB_BTREE : constant DBTYPE := 1;
DB_HASH : constant DBTYPE := 2;
etc

Sometimes using an integer type to map to a C enum type is the better
choice.


> The second hurdle I'll need to jump is creating a suitable Ada
> replacement for this buttload of defines that occur after the DBTYPE
> declaration.
> 
> /*
>  * DB access method and cursor operation values.  Each value is an operation
>  * code to which additional bit flags are added.
>  */
> #define	DB_AFTER	 1		/* c_put() */
> #define	DB_APPEND	 2		/* put() */
> #define	DB_BEFORE	 3		/* c_put() */

Just use named numbers:

DB_AFTER : constant := 1;
DB_APPEND : constant := 2;
DB_BEFORE : constant := 3;
etc



  parent reply	other threads:[~2003-07-31 17:34 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-07-30 20:03 Importing C structs? Freejack
2003-07-30 20:52 ` chris
2003-07-30 21:26   ` Freejack
2003-07-30 23:50   ` tmoran
2003-07-31 10:53     ` chris
2003-08-04 14:33     ` Andreas Almroth
2003-08-04 15:16       ` Samuel Tardieu
2003-08-04 20:07         ` Randy Brukardt
2003-07-31 17:14   ` Warren W. Gay VE3WWG
2003-08-12  0:02     ` chris
2003-07-31 18:17   ` Xenos
2003-07-31 19:16     ` Simon Wright
2003-07-31 20:17       ` Samuel Tardieu
2003-07-31 20:40       ` Xenos
2003-07-30 23:14 ` Ching Bon Lam
2003-07-31  0:07   ` tmoran
2003-07-31  5:35   ` Matthew Heaney
2003-07-31  7:46     ` Freejack
2003-07-31  9:27       ` Martin Dowie
2003-07-31 21:41         ` Freejack
2003-08-01  7:39           ` Martin Dowie
2003-07-31 17:34       ` Matthew Heaney [this message]
2003-07-31 11:29     ` Ching Bon Lam
2003-07-31 16:59       ` Matthew Heaney
2003-07-31 17:32         ` Warren W. Gay VE3WWG
2003-07-31 17:13       ` Matthew Heaney
2003-07-31 17:40       ` Randy Brukardt
2003-07-31  5:21 ` Matthew Heaney
replies disabled

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