[C2hs] Marshal Haskell list into monolithic arrays
zhu Jun
lilozhu at hotmail.com
Thu Aug 17 17:39:27 EDT 2006
Hi Udo and Duncan,
Yes, I made a mistake in C syntax.
Now, I call the function in Haskell like this:
-------------------------
lowPassFilter :: [CFloat] -> CFloat
lowPassFilter fs = (unsafePerformIO (lowPassFilterWrap fs))
where lowPassFilterWrap :: [CFloat] -> IO CFloat
lowPassFilterWrap fs = do
mfs <- newArray fs
fsP2 <- malloc
r <- f_lowPassFilter mfs fsP2
returnF <- peek fsP2
return returnF
foreign import ccall "static fmr.h lowPassFilter"
f_lowPassFilter :: Ptr (CFloat) -> Ptr (CFloat) -> IO (())
---------------------------
and the C function is defined as:
////////////////////////
void lowPassFilter(float *buff, float *sum)
{
// Work part
for (i = 0; i < NUM_TAPS; i++)
{
printf("buff %d = %f \n", i, *(buff++));
*sum += *(buff++) * coeff[i];
}
}
////////////////////////
It works well! Thank you so much!
Best wishes,
Yours,
Jun
>From: Udo Stenzel <u.stenzel at web.de>
>To: zhu Jun <lilozhu at hotmail.com>
>Subject: Re: [C2hs] Marshal Haskell list into monolithic arrays
>Date: Thu, 17 Aug 2006 17:17:21 +0200
>
>zhu Jun wrote:
> > There is a 'newArray' operation in MarshallArray to marshal Haskell
list,
> >
> > The C function looks like:
> > ////////////////////
> > void lowPassFilter(float *fs[10], float *sum)
>
>This function doesn't take (a pointer to) an array of floats, but (a
>pointer to) an array of pointers to floats, which I doubt was your
>intention. You need help programming in C, not help using C2HS. Try a
>book or ask in news:comp.lang.c
>
>
>Udo.
>
><< signature.asc >>
More information about the C2hs
mailing list