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,610e53a911ec64b3,start X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 1995-03-22 23:55:27 PST Path: nntp.gmd.de!stern.fokus.gmd.de!ceres.fokus.gmd.de!zib-berlin.de!news.mathworks.com!news.alpha.net!uwm.edu!cs.utexas.edu!swrinde!gatech!newsfeed.pitt.edu!uunet!intrepid.intrepid.com!usenet From: vladimir@speedy.intrepid.com (Vladimir Vukicevic) Newsgroups: comp.lang.ada Subject: Re: Importing C Structures Date: 23 Mar 1995 07:55:27 GMT Organization: Intrepid Technology, Inc. Message-ID: References: <3kr4q3$jd9@newsflash.concordia.ca> NNTP-Posting-Host: speedy.intrepid.com In-reply-to: ct_oreg@vega.concordia.ca's message of 23 Mar 1995 06:34:43 GMT Date: 1995-03-23T07:55:27+00:00 List-Id: In article <3kr4q3$jd9@newsflash.concordia.ca> ct_oreg@vega.concordia.ca (Chris O'Regan) writes: > > For my Real-Time Systems project, my partner and I are writing a program > to control a train set. We will be working on an Indy using GNAT 2.03, and > as little C code as possible. > > We need to interface the Indy's serial port. We have some documention > which explains how to do this in standard C, but we would prefer to do this > in Ada. We figure that we will need to import the functions and types from > the standard C library. > > Importing a function isn't a problem, but what about data types? > Rationale and the Reference Manual claim that it is possible, but without an > sample code snippet, we don't know where to begin. > > Could someone shed some light on the subject? Or should we give in and > write our serial port routines in C? No. Write them in Ada. :-) First, decide which functions you'll need. I'm assuming open (), read(), write(), ioctl() and the like. open () returns an int, so that's no problem. read/write would use Interfaces.C.Strings. ioctl () would use System.Address and others. If you need to pass around pointers, and don't care what they point to, treat them as System.Addresses. If there is some some struct that you need to map to Ada, it should be farily straightforward. i.e. typedef struct { int foo; char bar[10]; long *q; } A_Struct; becomes with Interfaces.C; package IC renames Interfaces.C; type A_Struct is record foo : IC.int; bar : IC.char_array (1 .. 10); q : access IC.long; end record; - Vladimir