Nick Sabalausky (Abscissa) wrote:
On 03/06/2017 08:27 PM, Andrei Alexandrescu wrote:* A struct S { int x; } compares differently on little endian and big endian system (!)This one is very surprising. How is that so, if both structs being compared are of the same endian-ness?
if we're talking about equality, yes. but opCmp is "less/greater" comparison. so, 0x290a will be:
0x0a 0x29 on little-endian, and: 0x29 0x0a on big-endian. let's take 0x1930, and compare it with 0x290a, using memcmp: for big-endian, first byte: 0x29:0x19: hit, 0x290a is greater. for little-endian, first byte: 0x0a:0x30: hit, 0x290a is *lesser* than 0x1930. oops.
