Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // hdr.h
- char **strings(int *count);
- // bdy.c
- #include "hdr.h"
- char *data[] = {"now", "is", "the", "time"};
- char **strings(int *count) {
- *count = sizeof(data) / sizeof(char*);
- return data;
- }
- -- caller.adb
- with Ada.Text_IO;
- with Ada.Unchecked_Conversion;
- with Interfaces.C.Strings;
- with System;
- procedure Caller is
- function Strings return Interfaces.C.Strings.chars_ptr_array;
- function Strings return Interfaces.C.Strings.chars_ptr_array is
- function Inner (Count : out Interfaces.C.int) return System.Address
- with
- Import,
- Convention => C,
- External_Name => "strings";
- Count : aliased Interfaces.C.int;
- Address : System.Address;
- begin
- Address := Inner (Count);
- declare
- subtype Result_Type
- is Interfaces.C.Strings.chars_ptr_array
- (1 .. Interfaces.C.size_t (Count));
- type Result_Type_P is access Result_Type;
- function Convert is new Ada.Unchecked_Conversion (System.Address,
- Result_Type_P);
- begin
- return Result : Result_Type do
- Result := Convert (Address).all;
- end return;
- end;
- end Strings;
- Answer : Interfaces.C.Strings.chars_ptr_array := Strings;
- begin
- for Str of Strings loop
- Ada.Text_IO.Put_Line (Interfaces.C.Strings.Value (Str));
- end loop;
- end Caller;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement