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=-0.9 required=5.0 tests=BAYES_00,FORGED_GMAIL_RCVD, FREEMAIL_FROM autolearn=no autolearn_force=no version=3.4.4 X-Received: by 2002:a5e:d618:: with SMTP id w24mr17145702iom.164.1553493496498; Sun, 24 Mar 2019 22:58:16 -0700 (PDT) X-Received: by 2002:aca:5184:: with SMTP id f126mr10050210oib.44.1553493496269; Sun, 24 Mar 2019 22:58:16 -0700 (PDT) Path: eternal-september.org!reader01.eternal-september.org!feeder.eternal-september.org!news.gegeweb.eu!gegeweb.org!usenet-fr.net!proxad.net!feeder1-2.proxad.net!209.85.166.215.MISMATCH!78no583741itl.0!news-out.google.com!l81ni590itl.0!nntp.google.com!w126no582594ita.0!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail Newsgroups: comp.lang.ada Date: Sun, 24 Mar 2019 22:58:15 -0700 (PDT) In-Reply-To: Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=70.109.61.2; posting-account=QF6XPQoAAABce2NyPxxDAaKdAkN6RgAf NNTP-Posting-Host: 70.109.61.2 References: User-Agent: G2/1.0 MIME-Version: 1.0 Message-ID: <53581698-0b8e-48d7-90e9-fe336ec19482@googlegroups.com> Subject: Re: differences between Ada and C in gnat forcing me to use C instead of Ada From: Jere Injection-Date: Mon, 25 Mar 2019 05:58:16 +0000 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Xref: reader01.eternal-september.org comp.lang.ada:55949 Date: 2019-03-24T22:58:15-07:00 List-Id: On Monday, March 25, 2019 at 1:46:07 AM UTC-4, matthewbr...@gmail.com wrote= : > Hi all: >=20 > I really want to use Ada. But gnat is forcing me to use C. Basically, I= wanted to interface with my scanner using SANE (Scanner Access Now Easy). = Using my "real" Debian machine since gnat doesn't work under Windows 10 (D= ebian subsystem for Linux), I created the ada specs from the C headers and = the sizes in C and Ada are different. For example: >=20 > In C, this code: > printf("sizeof(char *)=3D%d\n", sizeof(char *)); >=20 > prints "sizeof(char *)=3D8" >=20 >=20 > and this code: > printf("sizeof(SANE_Device)=3D%d\n", sizeof(SANE_Device)); >=20 > prints "sizeof(SANE_Device)=3D32". In C, the header defines it this way: >=20 > typedef char SANE_Char; > typedef const SANE_Char *SANE_String_Const; >=20 > typedef struct > { > SANE_String_Const name; /* unique device name */ > SANE_String_Const vendor; /* device vendor string */ > SANE_String_Const model; /* device model name */ > SANE_String_Const type; /* device type (e.g., "flatbed scanner") */ > } > SANE_Device; >=20 > which makes sense to me since 8*4 =3D 32 (sizeof(char *) * 4 elements in = the record. But on the Ada side, I get the following code: >=20 > Text_Io.Put_Line ("sane_sane_h.SANE_Device'Size=3D>" &=20 > Integer'Image (sane_sane_h.SANE_Device'Size)); >=20 > to print "sane_sane_h.SANE_Device'Size=3D> 256" >=20 > And sure enough "Integer'Image (InterfaceS.C.Strings.chars_ptr'Size))" pr= ints out 64. Now, how can we interface to a C library passing around the '= Address of an array of pointers to records if the elements in the record ar= e different sizes. No wonder, I get back garbage when calling sane_get_dev= ices. How is it that "sizeof(char *) is 8 in C and InterfaceS.C.Strings.cha= rs_ptr'Size is 64 in Ada. When I try to rep spec it, I get So when you do sizeof() in C it returns the number of bytes. When you do 'Size in Ada, it gives the number of bits. 8bits * 8bytes is 64 bits, so everything looks correct. They are returning the same effective size in both C and Ada.