/* memory byte ordering * * * output on a sparc-based machine (big-endian) * * processor type: * sparc * * address of a = 0x00020ae0, a is 0x01234567 * address of b = 0x00020ae0, b is 0x01, 0x23, 0x45, 0x67 * * address of c[0] = 0x00020930, c[0] is a * address of c[1] = 0x00020931, c[1] is b * address of c[2] = 0x00020932, c[2] is c * address of c[3] = 0x00020933, c[3] is d * address of c[4] = 0x00020934, c[4] is e * address of c[5] = 0x00020935, c[5] is f * address of c[6] = 0x00020936, c[6] is g * address of c[7] = 0x00020937, c[7] is * * * output on an intel-based machine (little-endian) * * processor type: * i386 * * address of a = 0x08060ac8, a is 0x01234567 * address of b = 0x08060ac8, b is 0x67, 0x45, 0x23, 0x01 * * address of c[0] = 0x08060a9c, c[0] is a * address of c[1] = 0x08060a9d, c[1] is b * address of c[2] = 0x08060a9e, c[2] is c * address of c[3] = 0x08060a9f, c[3] is d * address of c[4] = 0x08060aa0, c[4] is e * address of c[5] = 0x08060aa1, c[5] is f * address of c[6] = 0x08060aa2, c[6] is g * address of c[7] = 0x08060aa3, c[7] is * */ #include union{ int a; char b[4]; } word_value; char c[8] = "abcdefg"; int main(void){ int i; printf("processor type:\n"); fflush(NULL); system("uname -p"); printf("\n"); word_value.a = 0x01234567; printf("address of a = 0x%08x, a is 0x%08x\n",&word_value.a,word_value.a); printf("address of b = 0x%08x",word_value.b); printf(", b is 0x%02x, 0x%02x, 0x%02x, 0x%02x\n\n",word_value.b[0], word_value.b[1],word_value.b[2],word_value.b[3]); for(i=0; i<8; i++){ printf("address of c[%d] = 0x%08x, c[%d] is %c\n",i,&c[i],i,c[i]); } }