Commit | Line | Data |
---|---|---|
7f918cf1 CE |
1 | /* Copyright (C) 2012 Matthew Fluet. |
2 | * Copyright (C) 1999-2006 Henry Cejtin, Matthew Fluet, Suresh | |
3 | * Jagannathan, and Stephen Weeks. | |
4 | * Copyright (C) 1997-2000 NEC Research Institute. | |
5 | * | |
6 | * MLton is released under a BSD-style license. | |
7 | * See the file MLton-LICENSE for details. | |
8 | */ | |
9 | ||
10 | static inline bool isBigEndian(void) { | |
11 | uint16_t x = 0xABCDU; | |
12 | uint8_t y = 0; | |
13 | /* gcc optimizes the following code to just return the result. */ | |
14 | memcpy(&y, &x, sizeof(uint8_t)); | |
15 | if (y == 0xAB) return TRUE; /* big endian */ | |
16 | if (y == 0xCD) return FALSE; /* little endian */ | |
17 | die ("Could not detect endian --- neither big nor little!\n"); | |
18 | // return 0; | |
19 | } | |
20 | ||
21 | static inline bool isLittleEndian(void) { | |
22 | return not (isBigEndian()); | |
23 | } |