This is the mail archive of the libffi-discuss@sourceware.org mailing list for the libffi project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Function pointers?


I can pass pointers as arguments to a function without issue unless it
is a function pointer.  When I try and pass a function pointer, it
gets jumbled during the pass.  What am I doing wrong?

Here is an example code that prints the value of the pointer before
its passed, and in the function its passed to.  Both values are
different, does anyone know why?

(I am running OS X 10.8.2)

#include <stdio.h>
#include <ffi.h>

int test_a(void*ptr)
{ return 0; }

int test_b(void*ptr)
{
    printf("Address of passed ptr: %p\n", ptr );
    return 0;
}

int main()
{
    ffi_cif cif;
    ffi_type *args[1];
    void *values[1];
    int rc;

    args[0] = &ffi_type_pointer;
    values[0] = &test_a;

    if (ffi_prep_cif(&cif, FFI_DEFAULT_ABI, 1, &ffi_type_uint, args) == FFI_OK)
     {
       printf("Address of ptr to pass: %p\n", values[0] );
       ffi_call(&cif, test_b, &rc, values);
     }
     return 0;
}


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]