From 8aecb7b68103a4003d33d5764d696ebd04a673ed Mon Sep 17 00:00:00 2001 From: Aryadev Chavali Date: Sun, 28 Apr 2024 22:17:51 +0530 Subject: [PATCH] Fixed problem with detecting little endian Copied the code from stack overflow without thinking about it. The first byte in little endian order should always be LSB so I construct a more contrived example (0xFFFF0000) which should make it easier to detect what the first byte is considered on the machine. If it's 0 then the LSB is the first byte hence little endian, otherwise it's big endian. On a greater note: Don't never copy no code from stack overflow, bro. I went up there at 11 o'clock last night trynna get me some code. Bro, I copied that shit, woke up, my motherfucking LITTLE_ENDIAN detection don't work. Explain, bro. --- lib/base.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/base.h b/lib/base.h index 22d9a11..02663c2 100644 --- a/lib/base.h +++ b/lib/base.h @@ -99,7 +99,7 @@ typedef enum // Macro to determine little endian #ifndef LITTLE_ENDIAN -static const int __i = 1; +static const hword_t __i = 0xFFFF0000; #define LITTLE_ENDIAN ((*((byte_t *)&__i)) == 0) #endif