[Haskell-cafe] Endian conversion
Mark Carroll
markc at chiark.greenend.org.uk
Mon Oct 3 16:54:15 EDT 2005
On Mon, 3 Oct 2005, Joel Reymont wrote:
> On Oct 3, 2005, at 6:51 AM, Marc Ziegert wrote:
>
> > data (Integral a) => BigEndian a = BigEndian a deriving
> > (Eq,Ord,Enum,...)
> > be = $( (1::CChar)/=(unsafePerformIO $ with (1::CInt) $ peekByteOff
> > `flip` 0) ) :: Bool
>
> Will this always correctly determine if the platform is big-endian?
> How does it actually work?
I don't know, having not used things like peekByteOff, but my suspicion
would be that it's rather like,
typedef char byte;
char cChar = 1;
int cInt = 1;
int be = cChar != *(((byte*) &cInt) + 0);
printf("be = %i\n", be);
return 0;
in C, so it's looking to see if the first byte of the int representation
of 1 isn't 1.
-- Mark
More information about the Haskell-Cafe
mailing list