
On 2005-01-16, Aaron Denney
Basically, what's the best way to deal with C99's complex types? Pragmatically, how do I deal with them in function definitions now?
Is there any chance they'll get added to a later version of the FFI addendum?
So, I have heard claims that C 99 specifies that a variable v of type "complex t" is stored as if declared as t v[2], with v[0] the real part and v[1] the imaginary part. I don't have a copy of the spec at hand. Could someone who does verify this? If this is true, then the following should be a valid Storable instance: -- {poke,peek}{Elem,Byte}Off defaulted instance (RealFloat a, Storable a) => Storable (Complex a) where sizeOf (a :+ b) = 2 * sizeOf a alignment (a :+ b) = alignment a poke x (a :+ b) = do let y = castPtr x poke y a pokeElemOff y 1 b peek x = do let y = castPtr x a <- peek y b <- peekElemOff y 1 return (a :+ b) Would providing the the ElemOff or the ByteOff methods instead be any more efficient? -- Aaron Denney -><-