'How to test your code on a machine with big-endian architecture?

Both ideone.com and codepad.org have Little-Endian architechtures.

I want to test my code on some machine with Big-Endian architechture (for example - Solaris - which I don't have). Is there some easy way that you know about?



Solution 1:[1]

QEMU supports emulating several big-endian architectures. Note that some architectures support both endiannesses; some (Itanium, ARM) are primarily used as little-endian while others (PowerPC, MIPS) are primarily used as big-endian.

Aurélien Jarno wrote some HOWTOs on installing Debian on an emulated MIPS or SPARC machine which should be a good start.

Solution 2:[2]

If you are using Ubuntu, you can download MIPS cross compiler (or any other big-endian architecture that is supported by QEMU, and has a prebuilt cross compiler), and QEMU-user, then compile your code in static linkage, and just run it.

sudo apt-get install gcc-multilib-mips-linux-gnu gcc-mips-linux-gnu qemu-user

and then

mips-linux-gnu-gcc test.c -o test -static
qemu-mips ./test

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Nicholas Riley
Solution 2