I have a piece of code and its generating different output when run on centOS and RHEL systems and both are little-endian machines. RHEL: result is 0 Cent OS: result is -4
#include <stdio.h>
#include <string.h>
typedef unsigned short U16;
typedef unsigned char U8;
int main(void)
{
U16 num1 = 1;
U16 num2 = 5;
short int ret;
U8* s1 = (U8*)&num1;
U8* s2 = (U8*)&num2;
ret = memcmp((void*)s1, (void*)s2, (size_t) sizeof(U16));
printf("result is %d\n", ret);
return 0;
}
In both cases I am expecting output non-zero but its not. Also If I change 'ret' type to 'int' from 'short int' then output is non-zero for both cases. So, what's wrong when 'ret' declared as 'short int' ?