I'm still working on that damn Linux port, and I think the problem I'm having is the Big vs Little Endian difference of Intel vs mainframe...
The code has a LOT of pointer casting, and I've been seeing strange results in the debug code I added, so I wrote a simple test program so I could brush up on the basics of pointer casting in C.
Here is my test program:
Code:
#include <stdio.h>
int main()
{
int n;
char str[9] = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 };
int i = 0x12345678;
long l = 0x12345678;
short s[2] = { 0x1234, 0x5678 };
printf( "str = 0x%p, &str = 0x%p\n", str, &str );
printf( "*(int*)str = 0x%x, *(long*)str = 0x%x\n", *(int*)str, *(long*)str );
for ( n = 0; n < 8; n += 4 )
{
printf( "*(short*)str[%d] = 0x%x, ", n, *(short*)(&str[n]) );
printf( "(short)str[%d] = 0x%x\n", n, (short)str[n] );
}
printf( "i = 0x%x, (short)i = 0x%x\n", i, (short)i );
printf( "l = 0x%x, (short)l = 0x%x\n", l, (short)l );
printf( "s[0] = 0x%x, s[1] = 0x%x, *(int*)s = 0x%x, *(long*)s = 0x%x\n", s[0], s[1], *(int*)s, *(long*)s );
return 0;
}
and these are the results I get:
Code:
str = 0x0012FF48, &str = 0x0012FF48
*(int*)str = 0x4030201, *(long*)str = 0x4030201
*(short*)str[0] = 0x201, (short)str[0] = 0x1
*(short*)str[4] = 0x605, (short)str[4] = 0x5
i = 0x12345678, (short)i = 0x5678
l = 0x12345678, (short)l = 0x5678
s[0] = 0x1234, s[1] = 0x5678, *(int*)s = 0x56781234, *(long*)s = 0x56781234
Everything I see is what I expected to see, except for the parts in bold.
Can someone explain where those values came from?
This is what I was expecting to see:
Code:
*(int*)str = 0x12345678, *(long*)str = 0x12345678
*(short*)str[0] = 0x1234
*(short*)str[4] = 0x5678