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=unavailable autolearn_force=no version=3.4.4 X-Received: by 10.129.154.198 with SMTP id r189mr5134359ywg.142.1503023038556; Thu, 17 Aug 2017 19:23:58 -0700 (PDT) X-Received: by 10.36.57.129 with SMTP id l123mr20031ita.3.1503023038499; Thu, 17 Aug 2017 19:23:58 -0700 (PDT) Path: eternal-september.org!reader01.eternal-september.org!reader02.eternal-september.org!news.eternal-september.org!news.eternal-september.org!feeder.eternal-september.org!border1.nntp.ams1.giganews.com!nntp.giganews.com!peer01.ams1!peer.ams1.xlned.com!news.xlned.com!peer02.am4!peer.am4.highwinds-media.com!peer02.iad!feed-me.highwinds-media.com!news.highwinds-media.com!v49no1495238qtc.0!news-out.google.com!1ni1085itx.0!nntp.google.com!f16no104460itb.0!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail Newsgroups: comp.lang.ada Date: Thu, 17 Aug 2017 19:23:58 -0700 (PDT) Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=2607:fea8:3ce0:1bd:1cb5:8564:c3b9:7fe1; posting-account=cUi90woAAADTaOISowbbHM8GUD0-opJO NNTP-Posting-Host: 2607:fea8:3ce0:1bd:1cb5:8564:c3b9:7fe1 User-Agent: G2/1.0 MIME-Version: 1.0 Message-ID: <75d36301-5649-403b-b06f-7166196929c5@googlegroups.com> Subject: Please evaluate tiny binding that does not use Interfaces.C From: patrick@spellingbeewinnars.org Injection-Date: Fri, 18 Aug 2017 02:23:58 +0000 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Received-Body-CRC: 3520412212 X-Received-Bytes: 4284 Xref: news.eternal-september.org comp.lang.ada:47737 Date: 2017-08-17T19:23:58-07:00 List-Id: Hi Everyone It seems like everyone uses Interfaces.C when creating a C binding. I reali= ze that this makes the binding more portable. However, is there something to be said for small, easy to read code too? It seems that most bindings attempt to recreate C structs with records and = then create pointers to those records. Meanwhile, the binding does not acce= ss any members of that C struct directly. Those structs often have other st= ructs as members too and the process goes on and on. I realize that void pointers are dangerous but C is dangerous and I am wond= ering if my use is within good practices? My code is small and contains no exception handling and likely has lots of = other things missing like a gpr files and such but is the basic interfacing= between C and Ada okay? Do you see any pitfalls, aside from the fact that = it is calling C ? I personally find this very easy to write and read, I am hoping that this w= ill work out. Please let me know what you think ----------------------------------------------------------------- build.sh gnatmake -c terminal_app.adb=20 gnatmake -c ncurses_glue gcc-4.6 -c ncurses_glue.c=20 gnatbind terminal_app.ali ncurses_glue.ali gnatmake -c b~terminal_app.adb=20 gcc-4.6 terminal_app.o b~terminal_app.o ncurses_glue.o -o terminal_app -g= natwa -lncursesw -lgnat -gnato ----------------------------------------------------------------- -- test to see if library without interfaces.c will work out -- -- with ncurses_glue ; with ada.strings.fixed ; =20 procedure terminal_app is =20 package ng renames ncurses_glue ; package sf renames ada.strings.fixed ; =20 stdscr : access ng.WINDOW ; ret : integer ; str : string :=3D "test =E3=90=B4 " & ASCII.NUL ; =20 begin stdscr :=3D ng.initscr_plus ; ret :=3D ng.addstr(str) ; ret :=3D ng.refresh ; delay 2.0 ; ret :=3D ng.endwin ; end terminal_app ; ----------------------------------------------------------------- package ncurses_glue is type null_record is null record ; type WINDOW is access null_record ; function initscr_plus return Access WINDOW; pragma Import (C, initscr_plus, "initscr_plus"); function addstr (arg1 : string) return integer ; pragma Import (C, addstr, "addstr"); function refresh return integer; pragma Import (C, refresh, "refresh") ; function endwin return integer; pragma Import (C, endwin, "endwin") ; end ncurses_glue ; ----------------------------------------------------------------- #include #include void * initscr_plus() { setlocale(LC_CTYPE,""); initscr() ; return stdscr ; }