C compatible complex types using traits

But that could be changed since [f32; 2] and [f64; 2] currently aren't FFI-safe. They could be declared FFI-safe with _Complex's ABI.

(f64, f64) isn't FFI-safe either unless you make it #[repr(C)], but then it has the ABI of a struct, which differs from the ABI of _Complex on some platforms. I suppose you could declare the #[repr(Rust)] representation FFI-safe and give it _Complex's ABI, but I personally prefer making the array type FFI-safe and _Complex-compatible.

1 Like