[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Adding wide support to the Ada binding?

From: Patrick
Subject: Re: Adding wide support to the Ada binding?
Date: Sat, 19 Aug 2017 22:40:56 -0400
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Icedove/38.8.0

Hi Thomas

Thanks for answering my post !

Since I wrote it, I found out something and I am very happy about it.

As I was saying, I worked very hard to learn Ada in 2012 and I basically failed.

I now know why and I now hate Interfaces.C and the -fdump-ada-spec GCC switch, they ruined my Ada experience.

If we have Interfaces.C.int it is not compatible with a regular Ada integer. The hated library and tool above forces everyone to cast back and forth when in fact the regular built in Ada types are already compatible with C. In almost all cases Interfaces.C does nothing but get in the way.

I learned this from a long time Ada programmer on #ada on freenode but no one seems to use this, everyone is using Interfaces.C and -fdump-ada-spec dumps Interfaces.C code and it dump a massive amount of it.

If you are interested, I posted to the Ada list here:

My thread is dying. I am not sure if this is because no one cares or no one knows.

Please look at the current Ada ncurses binding, just like the other Ada bindings it recreates structs as records and then creates a pointer of that record's type. Meanwhile the members of that record/struct are not supposed to be accessed by the user, they should use the API.

There is no reason to create records within records within records. A pointer of the record's/struct's type can be created without recreating the record.

Please see this simple code. I am well on my way to being able to build a ncurses Ada binding without Interfaces.C.


         with ncurses_glue ;
         with ada.strings.fixed ;

         procedure terminal_app is

         package ng renames ncurses_glue ;
         package sf renames ada.strings.fixed ;

         stdscr : access ng.WINDOW ;
         ret    : integer ;
         str    : string := "test 㐴    " & ASCII.NUL ;
         ch     : character ;


          stdscr := ng.initscr_plus ;
          ret    := ng.addstr(str) ;
          ret    := ng.refresh ;
          ch     := ng.getch ;
          ret    := 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 getch
                  return character ;
                  pragma Import (C, getch, "getch") ;

         function endwin
                  return integer;
                  pragma Import (C, endwin, "endwin") ;

         end ncurses_glue ;


#include <ncursesw/ncurses.h>
#include <locale.h>

void * initscr_plus() {

  initscr() ;
  return stdscr ;


unicode already works!

It's easy to read, the C API could serve as documentation and with your new thread safe support, people could write code that blocks as usual for user input but also has tasks writing data to the screen at the same time.

Think of the possibilities, people could have stock information, sixel graphics or braille graphs plotting away as live graphs or text, while also blocking for user input !

I hope to bind most if not all of ncurses over the next few weeks. I actually want to use it with GnuCOBOL. This is my favourite language. It has an nucrses toolkit built right in. I have been given an experimental branch to add more ncurses functionality, hopefully my changes will be accepted.

If you would like, I can send all the Ada stuff to you to evaluate ? I can also send a build file for the samples I just posted, if you would like or if anyone watching this thread wants it?

There is no pressure to include anything in your great project, you could just see if you like it.

I am so happy. It was a punishing defeat to leave Ada after investing a year with it. Now I feel like I have that year back. I am going to have lots of fun blending C, Ada and COBOL

Have a great night-Patrick

reply via email to

[Prev in Thread] Current Thread [Next in Thread]