* Re: Strange problem [not found] <vhi3dsodsya.fsf@grotte.ifi.uio.no> @ 1999-12-30 0:00 ` Jerry van Dijk 2000-01-04 0:00 ` Matthew Heaney 0 siblings, 1 reply; 2+ messages in thread From: Jerry van Dijk @ 1999-12-30 0:00 UTC (permalink / raw) In article <vhi3dsodsya.fsf@grotte.ifi.uio.no> jankr@nntp.ifi.uio.no writes: >Why use words when you got code: Ok. :-) C: #include <stdio.h> void c_func (char *s, size_t len) { printf ("String: %s\n", s); printf ("Lenght: %d\n", len); } Ada: with Interfaces.C.Strings; procedure Demo is package C renames Interfaces.C; package CS renames Interfaces.C.Strings; procedure C_Func (s : CS.chars_ptr; len : C.size_t); pragma Import (C, C_Func, "c_func"); Test_String : constant String := "Hello, world!"; Str_Len : C.size_t := 0; Str_Ptr : CS.chars_ptr := CS.Null_Ptr; begin Str_Ptr := CS.New_String (Test_String); Str_Len := CS.Strlen (Str_Ptr); C_Func (Str_Ptr, Str_Len); CS.Free (Str_Ptr); end Demo; -- -- Jerry van Dijk | email: jdijk@acm.org -- Team-Ada | www: stad.dsl.nl/~jvandyk -- Paris, France | Leiden, Holland ^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: Strange problem 1999-12-30 0:00 ` Strange problem Jerry van Dijk @ 2000-01-04 0:00 ` Matthew Heaney 0 siblings, 0 replies; 2+ messages in thread From: Matthew Heaney @ 2000-01-04 0:00 UTC (permalink / raw) In article <946581540.11snx@jvdsys.stuyts.nl> , jerry@jvdsys.stuyts.nl (Jerry van Dijk) wrote: > In article <vhi3dsodsya.fsf@grotte.ifi.uio.no> jankr@nntp.ifi.uio.no writes: > > Ada: > > with Interfaces.C.Strings; > > procedure Demo is ... Here's an alternative implementation that does not require the use of heap: with Interfaces.C; procedure Demo is package C renames Interfaces.C; use type C.size_t; procedure C_Func (s : C.char_array; len : C.size_t); pragma Import (C, C_Func, "c_func"); Str : constant C.char_array := C.To_C ("Hello, world!"); begin C_Func (Str, Str'Length - 1); end Demo; ^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2000-01-04 0:00 UTC | newest] Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- [not found] <vhi3dsodsya.fsf@grotte.ifi.uio.no> 1999-12-30 0:00 ` Strange problem Jerry van Dijk 2000-01-04 0:00 ` Matthew Heaney
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox