This is the mail archive of the
libffi-discuss@sourceware.org
mailing list for the libffi project.
Re: [Question]pass structure by reference
ivo f <ivo.fried@gmx.net> writes:
>> libffi doesn't distinguish between different pointer types, since none
>> of the supported ABIs require this. They are all just pointers.
>
> I figured that out. But with libffi I can pass a structure for example:
>
> struct teststruct {
> int a;
> char b;
> }
>
> by telling the ffi_prep_cif function that I pass one struct which consist of
> an int and a char, and then I pass the ffi_call function two fitting values
> and what ffi does (in my understanding) is taking care or the padding and
> this stuff!
That's not quite right. ffi_call is expecting a pointer to a fully
populated teststruct. Look at struct1.c in the testsuite to see what I
mean.
AG
> But in order to let libffi take care of the padding and so on, I have to
> specify an ffi_type_struct and so I can't define an ffi_type_pointer to be
> passed. But what I want to do is letting libffi take care of the correct
> ordering of my attributes of the struct and pass everything as a pointer
> which would need me to specify the type in the ffi_prep_cif function as both
> or am I completely wrong?
>
> kind regards