(no title)
dandotway | 4 years ago
After so many years of endianness bugs in C/C++ code, it's perplexing that the web standards committee voted to put typed arrays in Javascript in such a way that exposes platform byte order to Javascript programmers who can't generally be expected to have low-level C/C++/ASM experience with memory layout issues:
function endianness () {
let u32arr = new Uint32Array([0x11223344]);
let u8arr = new Uint8Array(u32arr.buffer);
if (u8arr[0] === 0x44)
return 'Little Endian';
else if (u8arr[0] === 0x11)
return 'Big Endian';
else
return 'WTF (What a Terrible Failure)';
}
EDIT: my old Power Mac was big endian, but I just read POWER has an endianness toggle. So in little endian mode it ought run endian-buggy JS with bug-for-bug compatibility.
classichasclass|4 years ago