Quzah,
Yes, I had thought you might reply with something like that
Unfortunately, not everybody uses little endian machines
My output from your code:
Code:
arr[0] is 33554432
arr[1] is 33554432
arr[2] is 33554432
arr[3] is 33554432
arr[4] is 33554432
arr[5] is 33554432
arr[6] is 33554432
arr[7] is 33554432
arr[8] is 33554432
arr[9] is 33554432
My more portable version:
Code:
#include<string.h>
#include<stdio.h>
int bigendian;
int main( void )
{
int arr[10], x;
int y = 1;
if (*(char *)&y != 1)
bigendian = 1;
memset( arr, 0, sizeof arr );
for( x = 0; x < 10; x++ )
{
int *offset = arr + x;
if (bigendian)
offset = (char *)offset + sizeof(int)-1;
memset(offset, 2, 1 );
}
for( x = 0; x < 10; x++ )
{
printf("arr[%d] is %d\n", x, arr[x] );
}
return 0;
}