Big endian and little endian

Hi,
My question is if you wrote a program such as

1
2
3
4
5
6
7
#include <stdio.h>
 int main()
{
  unsigned short a;
  a = 0xfff4;
 printf("%x", &a);
 }


then compiled it with a little endian compiler, then it won't work correctly on a big endian machine right? it would need to be recompiled for their machine because I am setting it as it is rather than taking it in from an input? so it needs to be written to the executable in the correct order?
Last edited on
First, you have to fix the error: you cannot call printf with arguments of the wrong type, regardless of platform:

test.c:6:15: error: format specifies type 'unsigned int' but the argument has
      type 'unsigned short *' [-Werror,-Wformat]
 printf("%x", &a);
         ~~   ^~
1 error generated.


(and if you switch to something appropriate, such as printf("%p", &a), the behavior isn't platform-dependent)
Last edited on
Topic archived. No new replies allowed.