comp.lang.ada
 help / color / mirror / Atom feed
From: Mats Weber <Mats.Weber@elca-matrix.ch>
Subject: Re: HELP: Problem with C function called in Ada
Date: 1997/02/07
Date: 1997-02-07T00:00:00+00:00	[thread overview]
Message-ID: <32FB6616.5A2F@elca-matrix.ch> (raw)
In-Reply-To: Pine.SOL.3.95.970207144417.11551A-100000@java


> procedure keys is
> 
>  X: character;
> 
>  procedure Get_immediate(X:character);

Problem: should be X : out Character if you want something back from the
call.

>  pragma interface(C, Get_immediate);
>  pragma interface_name(Get_immediate,"getc");

Another problem: in C (I am not sure, but I think) getc is a function
and you should interface it as a function:

   function Get_immediate return Character;

>  package int_io is new text_io.integer_io(integer);
>  use int_io;
> 
>  begin
>   loop
>    Get_immediate(X);
>    Put_line(Natural'Image(character'pos(X)));
>    skip_line;
>   end loop;
>  end keys;
> 
> The following problems encountered are:
> 
> when I compile this code (ada keys.a, and ada -M keys -o keys.o), i
> obtain the following warning:
> Warning: variable may not have a value.

This is normal. With your original declaration of Get_Immediate, a call
is a read of the variable X (instead of a write if the paramter has mode
out). Reading uninitialized scalar variables is forbidden.

> If I run the code, I got a "Bus Error (code dumped)" !!!

that's probably a result of not interfacing getc correctly. If it's a
function, make it a function in Ada too.

> The warning disappear if I set a "X:=' '" just after the begin.

But not the core dump, right ?
This is normal (see above).

> The Put_line(Natural'...) is to obtain the code of the key pressed
> (especially arrow keys). Is it correct?

Beware of arrow keys: they often return more than on character (escape
sequences).




      parent reply	other threads:[~1997-02-07  0:00 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <Pine.SOL.3.95.970207144417.11551A-100000@java>
1997-02-07  0:00 ` HELP: Problem with C function called in Ada Robert A Duff
1997-02-07  0:00 ` Mats Weber [this message]
replies disabled

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