Judgment Conditional Compilation

I am reading Word from byte arrays and should make parts of my code endian-aware. Does the GHC MachDeps.h anything (e.g. MachDeps.h ) that I can use to make the code conditional based on processor consistency? If not, can I reliably derive validity from HOST_ARCH (from ghcplatform.h , available in a .cabal file with the conditional value arch() )? Or other ideas?

+5
source share
1 answer

You are looking for something like this: https://hackage.haskell.org/package/cpu-0.1.0/docs/System-Endian.html

If you do not want / cannot use these packages, looking at the source code for the above, you can see how to check compliance on any platform with (almost) any lower-level programming language such as C or similar. Fill part of your stack (for a machine with 4 bits: for example, 1000), and then read the LSB or MSB of the specified stack. Endianness will determine how it is stored (you will read 1000 or 0001).

+7
source

Source: https://habr.com/ru/post/1216466/


All Articles