This is the mail archive of the
libffi-discuss@sourceware.org
mailing list for the libffi project.
Re: Return values smaller than âintâ
- From: ludo at gnu dot org (Ludovic Courtès)
- To: libffi-discuss at sourceware dot org
- Date: Sun, 08 May 2011 15:44:30 +0200
- Subject: Re: Return values smaller than âintâ
- References: <878vukmfhc.fsf@gnu.org>
Hello,
I browsed the test suite and found that the correct way to do it is to
use âffi_argâ and suitably cast it:
--8<---------------cut here---------------start------------->8---
#include <ffi.h>
#include <stdlib.h>
#include <stdio.h>
#include <stdint.h>
#include <assert.h>
static uint16_t
foo (void)
{
return 0x9876U;
}
int
main (int argc, char *argv[])
{
ffi_cif cif;
ffi_arg rvalue;
if (FFI_OK != ffi_prep_cif (&cif, FFI_DEFAULT_ABI, 0,
&ffi_type_uint16, NULL))
abort ();
ffi_call (&cif, (void *) &foo, &rvalue, NULL);
printf ("-> %04x -- expected: %04x\n", (uint16_t) rvalue, foo ());
assert ((uint16_t) rvalue == foo ());
return 0;
}
--8<---------------cut here---------------end--------------->8---
Tested on x86_64, PPC64, and SPARC64.
Thanks,
Ludoâ.