Martin Pokorny <[EMAIL PROTECTED]> wrote,

> I've been working on an interface to BLAS recently, and I encountered
> a problem with a call to a C function having a `float' argument. The C
> function (declaration) is the following:
> 
> void cblas_saxpy(const int N, const float alpha, const float *X, const
> int incX, float *Y, const int incY);
> 
> When I use `foreign import' in ghc-4.08 in the most obvious way (at
> least with respect to the `alpha' arg), that is
> 
> foreign import "cblas_saxpy" unsafe
>   cblas_saxpy :: CInt -> CFloat -> ByteArray# -> CInt ->
>                  MutableByteArray# s -> CInt -> IO ()
> 
> my code does not produce correct results. However, when I wrap the
> `cblas_saxpy' function with a function uses a double arg for `alpha',
> and then demotes the value to a float before calling `cblas_saxpy', my
> code produces correct results. It appears to me that the FFI is
> producing a call to a K&R-style C function that promotes float
> arguments to double. If this is what is really happening, is there
> some way to change the default style of C-function call to ANSI? On
> the other hand, return values of either precision appear to work as I
> expect (I don't recall whether K&R also promote float return values to
> double).

This is due to a bug in the native code generator of GHC
4.08.  Compile via C with -fvia-C and you should be fine.

Cheers,
Manuel

Reply via email to