/* memory alignment * * * output on a sparc-based machine (accesses must be aligned) * * processor type: * sparc * * address of c = 0x00020820 * value of i = 0x01234567 * Bus error (core dumped) * * * output on an intel-based machine (unaligned accesses allowed) * (note also that this is little-endian) * * processor type: * i386 * * address of c = 0x0806099c * value of i = 0x67452301 * value of i = 0xab896745 * */ #include char c[8] = { 0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0 }; int main(void){ int i; printf("processor type:\n"); fflush(NULL); system("uname -p"); printf("\n"); printf("address of c = 0x%08x\n",c); fflush(NULL); i = *((int *) &c[0]); printf("value of i = 0x%08x\n",i); fflush(NULL); i = *((int *) &c[2]); printf("value of i = 0x%08x\n",i); }