SuperTails/langcraft

64-bit Endianness Inconsistency

5265644D61736F6E opened this issue · 1 comments

I tried running:

#include <stdint.h>

#include "mcinterface.h"

int t1 = -2;

int main() {
    print((uint64_t) ((long) t1) >> 32);
}

The expected output was -1 (0xFFFFFFFF) because -2 in hexadecimal is 0xFFFFFFFFFFFFFFFE. Instead, I got:

=== Begin output ===
-2
==== End output ====

The logical shift right interprets the operand as big endian while the type casting gives a little endian output.

For a shift of exactly 32 bits, it's supposed to copy the high byte of the input to the low byte of the output; but it was just copying low to low. Fixed in 46808a6.
Good catch!