From e854b00c2fb86a5f65e08d299bea64883cefb99c Mon Sep 17 00:00:00 2001 From: Dominik Vogt Date: Tue, 11 Nov 2014 13:55:22 +0100 Subject: [PATCH] Detect compiler's _Complex support by checking __STDC_NO_COMPLEX__. --- src/types.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/types.c b/src/types.c index ef4f151..5c7bd27 100644 --- a/src/types.c +++ b/src/types.c @@ -44,6 +44,7 @@ maybe_const ffi_type ffi_type_##name = { \ id, NULL \ } +#if !defined __STDC_NO_COMPLEX__ && defined __STDC_VERSION__ && (__STDC_VERSION__ >= 199901L) #define FFI_COMPLEX_TYPEDEF(name, type, maybe_const) \ static ffi_type *ffi_elements_complex_##name [2] = { \ (ffi_type *)(&ffi_type_##name), NULL \ @@ -58,6 +59,24 @@ maybe_const ffi_type ffi_type_complex_##name = { \ FFI_TYPE_COMPLEX, \ (ffi_type **)ffi_elements_complex_##name \ } +#else +/* Bogus definition for compilers without C99 complex support. */ +#define FFI_COMPLEX_TYPEDEF(name, type, maybe_const) \ +static ffi_type *ffi_elements_complex_##name [2] = { \ + (ffi_type *)(&ffi_type_##name), NULL \ +}; \ +struct struct_align_complex_##name { \ + char c; \ + type x; \ + type y; \ +}; \ +maybe_const ffi_type ffi_type_complex_##name = { \ + 2 * sizeof(type), \ + offsetof(struct struct_align_complex_##name, x), \ + FFI_TYPE_COMPLEX, \ + (ffi_type **)ffi_elements_complex_##name \ +} +#endif /* Size and alignment are fake here. They must not be 0. */ const ffi_type ffi_type_void = { -- 1.8.4.2