FrontISTR  5.7.0
Large-scale structural analysis program with finit element method
hecmw_vis_endian.h
Go to the documentation of this file.
1 /*****************************************************************************
2  * Copyright (c) 2019 FrontISTR Commons
3  * This software is released under the MIT License, see LICENSE.txt
4  *****************************************************************************/
5 
6 #ifndef HECMW_VIS_ENDIAN_H_INCLUDED
7 #define HECMW_VIS_ENDIAN_H_INCLUDED
8 
9 extern int IsLittleEndian(void);
10 
11 /******************************************************************************
12  FUNCTION: SwapEndian
13  PURPOSE: Swap the byte order of a structure
14  EXAMPLE: float F=123.456;; SWAP_FLOAT(F);
15  ******************************************************************************/
16 
17 #define SWAP_SHORT(Var) Var = *(short*)SwapEndian((void*)&Var, sizeof(short))
18 #define SWAP_INT(Var) Var = *(int*)SwapEndian((void*)&Var, sizeof(int))
19 #define SWAP_USHORT(Var) \
20  Var = *(unsigned short*)SwapEndian((void*)&Var, sizeof(short))
21 #define SWAP_LONG(Var) Var = *(long*)SwapEndian((void*)&Var, sizeof(long))
22 #define SWAP_ULONG(Var) \
23  Var = *(unsigned long*)SwapEndian((void*)&Var, sizeof(long))
24 #define SWAP_RGB(Var) Var = *(int*)SwapEndian((void*)&Var, 3)
25 #define SWAP_FLOAT(Var) Var = *(float*)SwapEndian((void*)&Var, sizeof(float))
26 #define SWAP_DOUBLE(Var) Var = *(double*)SwapEndian((void*)&Var, sizeof(double))
27 
28 extern void* SwapEndian(void* Addr, const int Nb);
29 
30 #endif /* HECMW_VIS_ENDIAN_H_INCLUDED */
SwapEndian
void * SwapEndian(void *Addr, const int Nb)
Definition: hecmw_vis_endian.c:18
IsLittleEndian
int IsLittleEndian(void)
Definition: hecmw_vis_endian.c:10