It seems, as if I have the questionable pleasure of
reporting the first bug in GHC 4.08:  The NCG passes floats
as doubles in foreign exports.

If the appended code is compiled with the NCG (ie, without
optimisation), the programs prints 0.0 instead of 101.0.  If
the C code is changed to use doubles instead of floats, the
correct result is returned.  When the original program is
compiled via C, the correct output is produced.

This is on i86/Linux.

BTW, if I am not mistaken, the FLOATS_AS_DOUBLES feature in
StgTypes.h will also lead to problems with the FFI if
invoked.  On an architecture where 

  sizeof (void *) == sizeof (double)

but sizeof (float) < sizeof (double), we won't have a proper
representation for `CTypes.CFloat'.  (Is there any such
architecture?)

Cheers,
Manuel

-- [ffifloat.hs] --
module Main 
where

foreign import ccall "bla.so" "foo" unsafe 
  foo :: Float -> IO Float

main :: IO ()
main  = do
          value <- foo 101.0
          print value

-- [ffifloat.h] --
#ifndef FFIFLOAT_H
#define FFIFLOAT_H

float foo (float x);

#endif

-- [ffifloat_c.c] --
float foo (float x)
{
  return x;
}

Reply via email to