Ordering comparisons
ketmar via Digitalmars-d
digitalmars-d at puremagic.com
Mon Mar 6 19:59:41 PST 2017
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.
More information about the Digitalmars-d
mailing list