From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-0.9 required=5.0 tests=BAYES_00,FORGED_GMAIL_RCVD, FREEMAIL_FROM autolearn=no autolearn_force=no version=3.4.4 X-Google-Thread: 103376,ea88e33ca617708,start X-Google-NewGroupId: yes X-Google-Attributes: gida07f3367d7,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Received: by 10.68.30.34 with SMTP id p2mr3766163pbh.4.1321645256232; Fri, 18 Nov 2011 11:40:56 -0800 (PST) Path: h5ni6657pba.0!nntp.google.com!news1.google.com!postnews.google.com!l19g2000yqc.googlegroups.com!not-for-mail From: awdorrin Newsgroups: comp.lang.ada Subject: Calling Ada Procedure from C - how to handle a char ptr/array Date: Fri, 18 Nov 2011 11:40:46 -0800 (PST) Organization: http://groups.google.com Message-ID: <8e5541a3-cdd5-40af-a6fd-f7539ee61326@l19g2000yqc.googlegroups.com> NNTP-Posting-Host: 192.91.173.36 Mime-Version: 1.0 X-Trace: posting.google.com 1321645256 26578 127.0.0.1 (18 Nov 2011 19:40:56 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Fri, 18 Nov 2011 19:40:56 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: l19g2000yqc.googlegroups.com; posting-host=192.91.173.36; posting-account=YkFdLgoAAADpWnfCBA6ZXMWTz2zHNd0j User-Agent: G2/1.0 X-Google-Web-Client: true X-Google-Header-Order: HUALESRCNK X-HTTP-UserAgent: Mozilla/5.0 (Windows NT 5.1; rv:8.0) Gecko/20100101 Firefox/8.0,gzip(gfe) Xref: news1.google.com comp.lang.ada:18970 Content-Type: text/plain; charset=ISO-8859-1 Date: 2011-11-18T11:40:46-08:00 List-Id: 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