[comp.lang.ada] calling Ada from C

mcragg@gmu90x.UUCP (Maureen Cragg) (10/16/88)

i have successfully called c functions from ada (the pragma import works fine),
but i'm having more difficulty the other way...

i'm trying to pass a string from c to ada:

extern void adaprint_s(char *str);
char str[81];
main(){
   puts("enter a string:");
   gets(str);
   adaprint_s(str);
}

package adaprint is

type string_ptr is access string(1..81);

procedure adaprint_s(
                     str : IN string_ptr );
pragma export_procedure(internal=>adaprint_s,external=>adaprint_s,
                        parameter_types=>(string_ptr));
end;

with text_io;
use text_io;
package body adaprint is

procedure adaprint_s(
                     str : IN string_ptr )
is
begin
   put("the string is:");
   put_line(str.all);
end;
end;

now it looks like i'm passing the address of a string to ada, which is expect-
ing a string pointer, but somehow my adaprint.str is set to the first 4 char-
acters of the string, in reverse order! (i've inspected the values with debug).

if i pass the address of the string pointer ( adaprint_s(&str); ) everything
works fine, but i'm at a loss to understand this behavior...

if anyone out there can explain this to me, i'll sleep better tonight;-)

and can anyone tell me how to pass a simple integer? i'm having less luck with
that...

adTHANXvance,
the air drummer

mcragg@gmu90x.UUCP (Maureen Cragg) (10/18/88)

In article <1512@gmu90x.UUCP>, mcragg@gmu90x.UUCP (Maureen Cragg) writes:
> and can anyone tell me how to pass a simple integer? i'm having less luck with
> that...

i've succeeded in passing an integer: adaprint(&i) where adaprint accepts
an integer...anyone care to explain that?

dbl7201@ttardis.UUCP (David B Lightstone) (02/24/91)

There is a possible backdoor strategy which may be used. I previously 
discussed this with Telesoft tech support cerca their version 1.3 and
version 1.5 (Motorola 68000 target, Vax host). 

The problem arose when I needed an interrupt handler, but needed
a response time on the order of 10 - 20 micro seconds. 

The strategy was never implemented, so I can not say if it will be 
successful. It was straight forward. When the assembler interrupt was
ready to complete  spin off another interrupt handler by changing
machine priority, restoring the registers, enabling interrupts and 
branching to a standard Ada Interrupt.

What prevents the C program from calling a software interrupt which
will be fielded by Ada? There will be logistical problem relatable to
exchanging data, so conventions will have to be established.

I don't consider this a clean solution.

When I discussed this approach with Telesoft is was not rejected out
of hand. Their implementation has changed substancially since then, so
there should be a much better solution somewhere.