Re: C chars_ptr STORAGE_ERROR in Imported function



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@xxxxxxxxxxxxxxx>, Kim Rostgaard Christensen <krc@xxxxxxxxxx> 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

.



Relevant Pages

  • Re: generic package with procedure paramter gives "not subtype conformant with declaration"
    ... Once i store the access in the pointer i no longer need to ... If the access values come from Ada, it gets a bit more complicated. ... package General_Conversion ... have the code that autogenerates wrappers for the avcall macros. ...
    (comp.lang.ada)
  • Re: Idiom for a class and an object in Ada
    ... you still have to declare them somewhere. ... declaration in the package body of the package that creates the class? ... > clear to me what you have against access types. ... with things having nothing to do with Ada and I don't see any need to do ...
    (comp.lang.ada)
  • Re: Instantiating private types with discriminants?
    ... Have I got to declare two new packages - one against ... is declared in the same package specification as T (same declarative ... Ada, you can also dispatch with plain variables, as illustrated above. ...
    (comp.lang.ada)
  • Re: Basic Explaination of OO in Ada
    ... package Pak_Vectors is ... Doesn't Ada.Containers.Indefinite_Vectors have to declare a class-wide ... access type from the user, and that's encapsulation at its best. ... In Ada, one rarely needs access types at all. ...
    (comp.lang.ada)
  • Re: Child Package Operator Visibility
    ... In fact, this sort of thing is an idiom I used to use a lot, before ... Ada 95 gave us "use type". ...  I would declare a package with the types I ...
    (comp.lang.ada)