Hello I'd like to work with 2d arrays:
--2d arrays
cArray :: IO (Ptr (Ptr CDouble))
cArray = do
x <- [C.block| double (*)[2] {
double (*ptd)[2] = malloc(sizeof(double[2][2]));
ptd[0][0] = 1.78;
ptd[0][1] = 1.68;
ptd[1][0] = 1.58;
ptd[1][1] = 1.48;
printf("the firstelement is: %f\n", ptd[1][1]);
return ptd;
}|]
return x
Then in another function:
e <- cArray :: IO (Ptr (Ptr CDouble))
e1 <- peekElemOff e 0 :: IO (Ptr CDouble)
e2 <- peekElemOff e1 0 :: IO CDouble
print e2
This always gives segment fault.
For 1-d array, i don't have problems.
Could anyone give me a hint?