comp.lang.ada
 help / color / mirror / Atom feed
* Get_Immediate has  raised  CONSTRAINT_ERROR : s-wchcnv.adb:207 explicit raise
@ 2015-02-18 17:29 darek
  2015-02-18 18:34 ` Dmitry A. Kazakov
                   ` (2 more replies)
  0 siblings, 3 replies; 10+ messages in thread
From: darek @ 2015-02-18 17:29 UTC (permalink / raw)


Dear All,
  reading from a keyboard  keys such as arrow keys, PgUp, PgDn, etc. seems to be a small challenge in Ada.  For this purpose one of the  Get_Immediate procedures from the Ada.Text_IO shall be used. For the keyboard we can use either 
  - procedure Get_Immediate  (Item : out Character) 
               or
  - procedure Get_Immediate  (Item      : out Character; Available : out Boolean)

When I have used the Get_Immediate procedure with the extra  boolean parameter, it  generates the constraint error for:
  - all arrow keys, PgUp, PgDn 
  - [ character from the keyboard !!!!

Is this a feature or a bug. How pressing a legal key can cause such a weird result? 


The Get_Immediate procedure without the boolean parameter works fine but it waits for a key to be pressed. 

System: Linux Testpc 3.11-2-amd64 #1 SMP Debian 3.11.8-1 (2013-11-13) x86_64 GNU/Linux (running as a guest inside the VirtualBox VM)
Compiler:gcc version 4.7.4 20140401 for GNAT GPL gpl-2014 (20140405) (GCC)

Any ideas how to avoid the problem with this exception? Am I missing something?

Cheers,
  Darek

The code:
with Ada.Text_IO;

procedure  TestKbd is

   package tIO renames Ada.Text_IO;

    procedure Test_Get_Immediate_No_Avail is 
      Char : Character;
   begin
      loop -- an infinite loop 
         tIO.Put_Line("Read key:"); 
         --| Here Get_Immediate is waiting for the input
         tIO.Get_Immediate(Char);
         tIO.Put_Line("Char ==>" & Character'Image(Char) & " code:" & Integer'Image(Character'Pos(Char)));      
         delay (0.1);
      end loop;
   end Test_Get_Immediate_No_Avail;
   
   procedure Test_Get_Immediate_With_Avail is
      Char : Character;
      Avail : Boolean;
   begin
      loop -- an infinite loop 
         tIO.Put_Line("Read key: "); 
         tIO.Get_Immediate(Char, Avail);
         if Avail then 
            tIO.Put_Line("Char ==>" & Character'Image(Char) & " code:" & Integer'Image(Character'Pos(Char)));          
         end if;         
         delay (1.0);
     end loop;
   end Test_Get_Immediate_With_Avail;
   
     
   
begin
   Test_Get_Immediate_With_Avail;
   --Test_Get_Immediate_No_Avail;
end TestKbd;



^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2015-02-19 21:37 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-02-18 17:29 Get_Immediate has raised CONSTRAINT_ERROR : s-wchcnv.adb:207 explicit raise darek
2015-02-18 18:34 ` Dmitry A. Kazakov
2015-02-18 19:34   ` darek
2015-02-18 20:36     ` Dmitry A. Kazakov
2015-02-18 21:19       ` darek
2015-02-18 21:44         ` Dmitry A. Kazakov
2015-02-18 22:09       ` Georg Bauhaus
2015-02-18 20:16 ` Simon Wright
2015-02-18 20:34   ` darek
2015-02-19 21:37 ` Björn Lundin

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox