obilittlebigman.h 1.91 KB
Newer Older
1 2 3 4 5 6 7 8 9
/****************************************************************************
 * Header file for endianness checking                                      *
 ****************************************************************************/

/**
 * @file obilittlebigman.h
 * @author Eric Coissac (eric.coissac@metabarcoding.org)
 * @date 23 May 2015
 * @brief Header file for endianness checking.
10 11
 */

12

13 14
#ifndef OBILITTLEBIGMAN_H_
#define OBILITTLEBIGMAN_H_
15

16

17 18
#include <stdbool.h>

19

20
/**
21
 * Test if the architecture of the processor is little endian.
22
 *
23
 * ##Two classes of CPU architecture can be defined:
24 25 26
 * 		- little endian
 * 		- big endian
 *
27 28 29 30 31
 * 	They describe the way the processor stores multi-byte values
 * 	in memory. If we consider a 32 bits integer value encoded in
 * 	hexadecimal `0x11223344`, this value needs four bytes to be
 * 	stored. These four bytes will have consecutive addresses in memory.
 * 	Let's say that these addresses will be : 01, 02, 03, and 04
32 33 34 35 36 37 38
 *
 * 	###A big endian architecture will store our integer with the following schema:
 *
 *	     Address |   01 |   02 |   03 |   04
 *	    ---------|------|------|------|------
 *       value   | Ox11 | Ox22 | 0x33 | 0x44
 *
39
 *  In this architecture, the last address (the end of the representation) is
40 41 42 43 44 45 46 47
 *  used to store the byte of higher weight (BIG ENDian)
 *
 * 	###A little endian architecture will store our integer with the following schema:
 *
 *	     Address |   01 |   02 |   03 |   04
 *	    ---------|------|------|------|------
 *       value   | Ox44 | Ox33 | 0x22 | 0x11
 *
48
 *  In this architecture, the last address is
49 50
 *  used to store the byte of lighter weight (LITTLE ENDian)
 *
51
 * @returns a `bool` value:
52 53 54
 * 		- `true`  if the architecture is little endian
 * 		- `false` if the architecture is big endian
 *
Eric Coissac committed
55 56
 * @since May 2015
 * @author Eric Coissac (eric.coissac@metabarcoding.org)
57
 */
58
bool obi_is_little_endian(void);
59 60


61
#endif /* OBILITTLEBIGMAN_H_ */