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.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,d71460587da14d5b X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2003-07-31 10:34:57 PST Path: archiver1.google.com!postnews1.google.com!not-for-mail From: mheaney@on2.com (Matthew Heaney) Newsgroups: comp.lang.ada Subject: Re: Importing C structs? Date: 31 Jul 2003 10:34:56 -0700 Organization: http://groups.google.com/ Message-ID: <1ec946d1.0307310934.223e1c71@posting.google.com> References: <1V1Wa.299$jp.55@newsread4.news.pas.earthlink.net> NNTP-Posting-Host: 66.162.65.162 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit X-Trace: posting.google.com 1059672897 31695 127.0.0.1 (31 Jul 2003 17:34:57 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: 31 Jul 2003 17:34:57 GMT Xref: archiver1.google.com comp.lang.ada:41094 Date: 2003-07-31T17:34:57+00:00 List-Id: Freejack wrote in message news:... > 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