Hugs ffi, sizeOf operator

Ross Paterson ross@soi.city.ac.uk
Tue, 7 Jan 2003 16:16:09 +0000


On Mon, Jan 06, 2003 at 03:42:27PM -0500, R. Legere wrote:
> I ran into a possible problem while testing some ffi code.
>  This is with hugs compiled for cygwin or with the windows (msi)  version.
> Hugs says: sizeOf x::CDouble is 4,
> wheras 'C' says sizeof(double) is 8.
> 
> I ~~think~~ I see what the problem is with sizeOf.  I am using the
> new hierarchical libs, and it defines sizeOf by hardcoding the sizes rather
> then asking 'c' like the previous versions did. And sizeOf Double is coded
> as 4 in libraries\Foreign\Storable.hs

Thanks for the report.  It's a bug on all architectures, now fixed in CVS.
(The sizes are computed in the configuration process, and there was some
confusion about doubles.)  A workaround is to change that 4 to an 8.

> As a side note, is alignPtr implemented somewhere?

Not in the Nov 2002 release.  The CVS version has

alignPtr :: Ptr a -> Int -> Ptr a
alignPtr p n = p `plusPtr` ((n - ptrToInt p `mod` n) `mod` n)