comp.lang.ada
 help / color / mirror / Atom feed
From: anon@anon.org (anon)
Subject: Re: C chars_ptr STORAGE_ERROR in Imported function
Date: Fri, 22 Aug 2008 18:48:44 GMT
Date: 2008-08-22T18:48:44+00:00	[thread overview]
Message-ID: <gSDrk.11330$Mh5.10289@bgtnsc04-news.ops.worldnet.att.net> (raw)
In-Reply-To: g8ltqo$7ir$1@jacob-sparre.dk

Because Char_Prt in "Interfaces.C.Strings" is a private Ada type that 
C function does not understand. You need to use "Interfaces.C.Pointer" 
package to build a C Char_Ptr pointer package.  And use those functions, 
etc.

A possibility that most teachers may frown about, but it does work is to 
switch the Ada pointers to "System.Address" and pass to the C functions.. 
Check out the "Interfaces.C.Extensions.ads" to see how the "void" and 
"void *" are handled, if the teachers dislike the idea.


In <g8ltqo$7ir$1@jacob-sparre.dk>, Kim Rostgaard Christensen <krc@greenpc.dk> writes:
>Hello there
>
>I am in progress of binding the pcap c library to ada, it is a part of a
>school project. And for that i need a funtion that modifies a parameter 
>to a function like so:
>
>char    *pcap_lookupdev(char *);
>
>I have figured out this much:
>
>  function pcap_lookupdev(errbuff : Interfaces.C.Strings.Chars_Ptr) 
>return Interfaces.C.Strings.Chars_Ptr;
>  pragma Import (C, pcap_lookupdev, "pcap_lookupdev");
>
>This works in the sense that running it as root returns the device 
>found, but when I run it as normal user I get
>
>raised STORAGE_ERROR : stack overflow (or erroneous memory access)
>
>Do I need to declare the buffer and then then pass its c pointer to the 
>function?
>
>It is declared like this in a c example:
>char errbuf[PCAP_ERRBUF_SIZE];
>
>Best
>Kim Rostgaard Christensen




  parent reply	other threads:[~2008-08-22 18:48 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-08-22  8:36 C chars_ptr STORAGE_ERROR in Imported function Kim Rostgaard Christensen
2008-08-22  9:03 ` Niklas Holsti
2008-08-22  9:55   ` Kim Rostgaard Christensen
2008-08-22 11:43     ` Niklas Holsti
2008-08-22 22:54       ` Kim Rostgaard Christensen
2008-08-22 18:48 ` anon [this message]
2008-08-22 21:55   ` tmoran
2008-08-23 10:11   ` Niklas Holsti
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox