gcc - Imitate/emulate a big-endian behavior in C? -


i wondering if it's possible emulate big-endian behavior, testing purpose?

via either windows or linux , mingw or gcc. here's sample of code emulation return big endian:

#include <stdio.h> #include <stdlib.h> #include <string.h>  #include <limits.h> #if char_bit != 8 #error "unsupported char size detecting endianness" #endif  int main (void) {   short int word = 0x0001;   char *byte = (char *) &word;   if (byte[0]) printf("little endian");   else printf("big endian");   return 0; } 

you can't switch endianes testing purposes or that. can is, install emulator big-endian architecture , compile program emulator. here's 1 way, under:

http://people.debian.org/~aurel32/qemu/

are debian disk images kinds of qemu supported architectures. mips, sparc , arm big-endian (do not download ending -el). i'm using debian lenny mips ( http://people.debian.org/~aurel32/qemu/mips/ ). install qemu platform, follow instructions on mips-page download image , kernel file.

now can boot debian 5 mips right console. login virtual machine, become super user (the password "root") , install c-compiler:

debian-mips:~# su - debian-mips:~# apt-get update debian-mips:~# apt-get install gcc 

fire editor , enter program:

debian-mips:~# pico foo.c debian-mips:~# gcc foo.c debian-mips:~# ./a.out big endian 

Comments

Popular posts from this blog

c++ - How do I get a multi line tooltip in MFC -

asp.net - In javascript how to find the height and width -

c# - DataTable to EnumerableRowCollection -