Reputation: 11
I have a C
code which is working fine on Solaris
machine but the same code is giving segmentation fault for sometimes and some other time producing different output.
The following is the part where I am getting difference in both the machines:
FILE *inf;
unsigned char *ptr;
unsigned short *ds;
int n, s;
char work[100];
inf = (FILE *) fopen("Filename", "r");
s = fseek(inf, 0, SEEK_SET);
n = fread(work, 1, sizeof(work), inf);
ptr = (unsigned char *)work;
ptr += 8;
count = 0;
ds = (unsigned short *) ptr;
count = *ds;
When I am printing the value of count it is 15
in Solaris
Machine and 768
in Linux
machine.
Please suggest me the changes to be done in code on Linux machine.
Upvotes: 1
Views: 282
Reputation: 4727
I don't think it's (just) the endianness. 15 = 0x000F. 768 = 0x0300. It might be related to the size of char though. Try printing CHAR_BIT on both machines and see what you get.
Upvotes: 2