2
* endianttest.h - Platform endian testing
3
* Copyright (C) 2011, D Haley
5
* This program is free software: you can redistribute it and/or modify
6
* it under the terms of the GNU General Public License as published by
7
* the Free Software Foundation, either version 3 of the License, or
8
* (at your option) any later version.
10
* This program is distributed in the hope that it will be useful,
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
* GNU General Public License for more details.
15
* You should have received a copy of the GNU General Public License
16
* along with this program. If not, see <http://www.gnu.org/licenses/>.
19
#ifndef _ENDIAN_TEST_H_
20
#define _ENDIAN_TEST_H_
21
#if defined (_WIN32) || defined(_WIN64) || defined(__CYGWIN__)
22
#define __LITTLE_ENDIAN__
30
//if both are not defined it is TRUE!
31
#if __BYTE_ORDER == __BIG_ENDIAN
32
#ifndef __BIG_ENDIAN__
33
#define __BIG_ENDIAN__
35
#elif __BYTE_ORDER == __LITTLE_ENDIAN
36
#ifndef __LITTLE_ENDIAN__
37
#define __LITTLE_ENDIAN__
39
#elif __BYTE_ORDER == __PDP_ENDIAN
40
#ifndef __ARM_ENDIAN__
41
#define __ARM_ENDIAN__
44
#error "Endian determination failed"
48
const int ENDIAN_TEST=1;
50
inline int is_bigendian() { return (*(char*)&ENDIAN_TEST) == 0 ;}
52
inline int is_littleendian() { return (*(char*)&ENDIAN_TEST) == 1 ;}
55
inline void floatSwapBytes(float *inFloat)
57
//Use a union to avoid strict-aliasing error