Re: [Haskell-cafe] GHC.Ptr, Foreign.Storable, Data.Storable.Endian, looking for good examples of usage

On 10 January 2011 16:36, Antoine Latter
wrote: On Mon, Jan 10, 2011 at 10:17 AM, Aaron Gray
wrote:
On 10 January 2011 16:13, Daniel Fischer < daniel.is.fischer@googlemail.com> wrote:
On Monday 10 January 2011 16:45:36, Aaron Gray wrote:
This is interesting, what does the following line do :-
data Int24 = I24# Int# deriving (Eq, Ord)
regarding the I24# and Int#, are these inbuilt ?
Int# is the raw machine int (4 or 8 bytes) and I24# is the
constructor.
GHC uses the magic hash '#' to denote raw unboxed types (and the constructors making ordinary boxed Haskell types from these, e.g. there's
data Int = I# Int# data Word = W# Word# data Double = D# Double#
and more defined in base [GHC.Types, GHC.Word]).
So the 24 bit value is actually stored as a 32bit value. Meaning I will have to do my own IO reader and writer code to a ByteString. Thanks, Aaron
I don't think so - the Storable instance provided for the Int24 type peeks and pokes 24-bit values. At least, that what I understand John's earlier message to mean.
Yes looking at the code it does support 24bit peeks and pokes.
This is correct (at least it's how it's meant to work). 24bit values are represented as 32bit words for ops, but peeks and pokes are 24bit. If all you want to do is read/write 24bit values there's nothing wrong with binary, but if you ever want to use them the Word24 and Int24 types are nice to have. John
participants (1)
-
John Lato