From: awdorrin <awdorrin@gmail.com>
Subject: Calling Ada Procedure from C - how to handle a char ptr/array
Date: Fri, 18 Nov 2011 11:40:46 -0800 (PST)
Date: 2011-11-18T11:40:46-08:00 [thread overview]
Message-ID: <8e5541a3-cdd5-40af-a6fd-f7539ee61326@l19g2000yqc.googlegroups.com> (raw)
What would be the recommended way to pass a C char pointer or char
array into an Ada function or procedure that will be called from a C
program?
After reading through the Interfaces.C.* packages, I'm assuming I
could do something like this:
In my Ada procedure:
procedure Get_Text( s : out Interfaces.C.char_array) is
Label : String(1..8)
begin
Label(1..8) == "12345678";
S := Interfaces.C.To_C(Label);
end;
with a C program that does the following:
int main() {
char temp[8+1];
memset( temp, '\0', 9);
adainit();
Get_Text(temp);
printf("Temp is: %s\n", temp);
adafinal();
}
however when I compile the code I get the following warning:
warning: type of argument "Get_Text.s" is unconstrained array
warning: foreign caller must pass bounds explicitly
Then when I run, I get an error from the following line of code: S :=
Interfaces.C.To_C(Label);
"raised CONSTRAINT_ERROR : length check failed.
What length check?
Is there a better way to be doing this?
Thanks!
-Al
next reply other threads:[~2011-11-18 19:40 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-11-18 19:40 awdorrin [this message]
2011-11-18 19:56 ` Calling Ada Procedure from C - how to handle a char ptr/array Jeffrey Carter
2011-11-18 20:19 ` awdorrin
2011-11-18 20:41 ` awdorrin
2011-11-18 21:38 ` Adam Beneschan
2011-11-18 22:32 ` Georg Bauhaus
2011-11-19 2:16 ` Adam Beneschan
2011-11-21 16:33 ` awdorrin
2011-11-22 13:20 ` awdorrin
2011-11-22 13:28 ` Simon Wright
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox