This is the mail archive of the
libffi-discuss@sourceware.org
mailing list for the libffi project.
Function returning uint16
- From: StÃphane Glondu <steph at glondu dot net>
- To: libffi-discuss at sourceware dot org
- Date: Thu, 16 Jun 2016 17:03:50 +0200
- Subject: Function returning uint16
- Authentication-results: sourceware.org; auth=none
Hello,
I am trying to debug
https://github.com/ocamllabs/ocaml-ctypes/issues/404
and I realized that the following code (on amd64):
#include <stdio.h>
#include <stdint.h>
#include <ffi.h>
uint16_t retrieve() {
return 0x4242;
}
int main() {
uint16_t r[2] = { 0xdead, 0xbeef };
ffi_cif cif;
printf("r = {%x, %x}\n", r[0], r[1]);
ffi_prep_cif(&cif, FFI_DEFAULT_ABI, 0, &ffi_type_uint16, NULL);
ffi_call(&cif, FFI_FN(retrieve), &r[0], NULL);
printf("r = {%x, %x}\n", r[0], r[1]);
return 0;
}
returns:
r = {dead, beef}
r = {4242, 0}
Is that expected? I don't expect r[1] to be overwritten...
Cheers,
--
StÃphane