* Re: HELP: Problem with C function called in Ada
[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
1 sibling, 0 replies; 2+ messages in thread
From: Mats Weber @ 1997-02-07 0:00 UTC (permalink / raw)
> 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).
^ permalink raw reply [flat|nested] 2+ messages in thread