[MLton] bool and MLton FFI
Wesley W. Terpstra
wesley@terpstra.ca
Fri, 23 Jun 2006 00:30:58 +0200
On Jun 23, 2006, at 12:08 AM, Matthew Fluet wrote:
> So, unlike int32_t and friends, there is no required size for a bool.
There is no required size for 'int' or 'short' either.
How is bool different in this respect?
> [fluet@localhost temp]$ gcc -o z z.c
> [fluet@localhost temp]$ ./z
> sizeof(bool) = 1
> sizeof(bool[5]) = 5
kiwiw:~/src terpstra$ gcc -o z z.c
kiwiw:~/src terpstra$ ./z
sizeof(bool) = 4
sizeof(bool[5]) = 20
(powerpc/osx)
> Point being that there may not be a universal choice for the
> representation of 'bool'. Furthermore, equating ML 'bool' with C
> 'bool' would seem to rule out a bit array implementation, though it
> does admit a word8 array implementation.
As long as we forbid bool vector in the FFI, then MLton is free to
store bools however it wants.
I don't see a problem with MLton converting whatever representation
it uses for bool to a C bool (of the appropriate type for that
system) automatically in the FFI. ie: Compare to zero when it's a
return value, or promote to 8/32 bits on call.