Re: Problems with FFI

"goobamarino" <[email protected]> Mon, 07 Apr 2003 13:43:33 -0000
Newsgroups gmane.lisp.corman
Message-ID <[email protected]>
Ok so going forward I assume the following:

The '&' character (taking the address of my variable) is implicit 
whenever a called function wants a pointer.

To clarify your example, I think it should be 

//prototype
void call_some_func(long* yourNumber);


   TYPEBLAH blah = 0;
   call_some_func(&blah);


If TYPEBLAH is a long int or int then your example is fine. There is 
no other way to update the value of blah. 

But if blah's memory will be allocated by the function in question 
than the following is more appropriate:

void call_some_func(TYPEBLAH** yourNumber);

   TYPEBLAH *pblah;
   call_some_func(&pblah);

This is what I would be doing most of the time with the FFI calls 
into the WIN32 API.


So if I see ** in the function prototype I declare TYPEBLAH* and if I 
see * in the function prototype I declare TYPEBLAH.

Thanks for the clarification Chris,
Wayne Rogers


--- In [email protected], Chris Double <chris.double@d...> 
wrote:
> On Tue, 08 Apr 2003 00:16, goobamarino wrote:
> > I guess what thouroughly confuses me is the occasions when a
> > declaration does look like (malloc (Sizeof 'somepointer)). 
> 
> It confused me too. Mainly because in C I'm so used to just doing:
> 
>   void* blah;
>   call_some_func(&blah);
> 
> or
> 
>   void* blah = &some_other_blah;
>   call_some_func(blah);
> 
> It took me awhile to understand that I have to actually allocate 
that pointer 
> value so there is somewhere to store the result.
> 
> > Is this merely so that when the resulting (cref somepointer ptr 
0) is
> > called the lisp knows what to do?
> 
> No, it's just a form of documentation I guess. All foreign pointers 
are 
> basically untyped and are really (:void *). It's cref that 
effectively casts 
> it and works out offsets, etc.
> 
> Chris.


------------------------ Yahoo! Groups Sponsor ---------------------~-->
Get 128 Bit SSL Encryption!
http://us.click.yahoo.com/xaxhjB/hdqFAA/VygGAA/SyjtlB/TM
---------------------------------------------------------------------~->

To unsubscribe from this group, send an email to:
[email protected]

 

Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/