libnx  v4.8.0
types.h
Go to the documentation of this file.
1 /**
2  * @file switch/types.h
3  * @brief Various system types.
4  * @copyright libnx Authors
5  */
6 #pragma once
7 
8 #include <stdint.h>
9 #include <stdbool.h>
10 #include <stddef.h>
11 #include <stdalign.h>
12 
13 #ifndef SSIZE_MAX
14 #ifdef SIZE_MAX
15 #define SSIZE_MAX ((SIZE_MAX) >> 1)
16 #endif
17 #endif
18 
19 typedef uint8_t u8; ///< 8-bit unsigned integer.
20 typedef uint16_t u16; ///< 16-bit unsigned integer.
21 typedef uint32_t u32; ///< 32-bit unsigned integer.
22 typedef uint64_t u64; ///< 64-bit unsigned integer.
23 typedef __uint128_t u128; ///< 128-bit unsigned integer.
24 
25 typedef int8_t s8; ///< 8-bit signed integer.
26 typedef int16_t s16; ///< 16-bit signed integer.
27 typedef int32_t s32; ///< 32-bit signed integer.
28 typedef int64_t s64; ///< 64-bit signed integer.
29 typedef __int128_t s128; ///< 128-bit unsigned integer.
30 
31 typedef volatile u8 vu8; ///< 8-bit volatile unsigned integer.
32 typedef volatile u16 vu16; ///< 16-bit volatile unsigned integer.
33 typedef volatile u32 vu32; ///< 32-bit volatile unsigned integer.
34 typedef volatile u64 vu64; ///< 64-bit volatile unsigned integer.
35 typedef volatile u128 vu128; ///< 128-bit volatile unsigned integer.
36 
37 typedef volatile s8 vs8; ///< 8-bit volatile signed integer.
38 typedef volatile s16 vs16; ///< 16-bit volatile signed integer.
39 typedef volatile s32 vs32; ///< 32-bit volatile signed integer.
40 typedef volatile s64 vs64; ///< 64-bit volatile signed integer.
41 typedef volatile s128 vs128; ///< 128-bit volatile signed integer.
42 
43 typedef u32 Handle; ///< Kernel object handle.
44 typedef u32 Result; ///< Function error code result type.
45 typedef void (*ThreadFunc)(void *); ///< Thread entrypoint function.
46 typedef void (*VoidFn)(void); ///< Function without arguments nor return value.
47 
48 typedef struct { u8 uuid[0x10]; } Uuid; ///< Unique identifier.
49 
50 typedef struct { float value[3]; } UtilFloat3; ///< 3 floats.
51 
52 /// Creates a bitmask from a bit number.
53 #ifndef BIT
54 #define BIT(n) (1U<<(n))
55 #endif
56 
57 #ifndef BITL
58 #define BITL(n) (1UL<<(n))
59 #endif
60 
61 /// Packs a struct so that it won't include padding bytes.
62 #ifndef NX_PACKED
63 #define NX_PACKED __attribute__((packed))
64 #endif
65 
66 /// Marks a function as not returning, for the purposes of compiler optimization.
67 #ifndef NX_NORETURN
68 #define NX_NORETURN __attribute__((noreturn))
69 #endif
70 
71 /// Performs a dummy operation on the specified argument in order to silence compiler warnings about unused arguments.
72 #ifndef NX_IGNORE_ARG
73 #define NX_IGNORE_ARG(x) (void)(x)
74 #endif
75 
76 /// Flags a function as deprecated.
77 #ifndef NX_DEPRECATED
78 #ifndef LIBNX_NO_DEPRECATION
79 #define NX_DEPRECATED __attribute__ ((deprecated))
80 #else
81 #define NX_DEPRECATED
82 #endif
83 #endif
84 
85 /// Flags a function as (always) inline.
86 #define NX_INLINE __attribute__((always_inline)) static inline
87 
88 /// Flags a function as constexpr in C++14 and above; or as (always) inline otherwise.
89 #if __cplusplus >= 201402L
90 #define NX_CONSTEXPR NX_INLINE constexpr
91 #else
92 #define NX_CONSTEXPR NX_INLINE
93 #endif
94 
95 /// Invalid handle.
96 #define INVALID_HANDLE ((Handle) 0)
Definition: types.h:50
Definition: types.h:48
__int128_t s128
128-bit unsigned integer.
Definition: types.h:29
volatile s8 vs8
8-bit volatile signed integer.
Definition: types.h:37
volatile u8 vu8
8-bit volatile unsigned integer.
Definition: types.h:31
int64_t s64
64-bit signed integer.
Definition: types.h:28
uint64_t u64
64-bit unsigned integer.
Definition: types.h:22
volatile u128 vu128
128-bit volatile unsigned integer.
Definition: types.h:35
volatile s64 vs64
64-bit volatile signed integer.
Definition: types.h:40
void(* VoidFn)(void)
Function without arguments nor return value.
Definition: types.h:46
volatile u16 vu16
16-bit volatile unsigned integer.
Definition: types.h:32
volatile s32 vs32
32-bit volatile signed integer.
Definition: types.h:39
volatile s128 vs128
128-bit volatile signed integer.
Definition: types.h:41
volatile s16 vs16
16-bit volatile signed integer.
Definition: types.h:38
void(* ThreadFunc)(void *)
Thread entrypoint function.
Definition: types.h:45
uint8_t u8
8-bit unsigned integer.
Definition: types.h:19
__uint128_t u128
128-bit unsigned integer.
Definition: types.h:23
int8_t s8
8-bit signed integer.
Definition: types.h:25
int16_t s16
16-bit signed integer.
Definition: types.h:26
u32 Handle
Kernel object handle.
Definition: types.h:43
volatile u32 vu32
32-bit volatile unsigned integer.
Definition: types.h:33
volatile u64 vu64
64-bit volatile unsigned integer.
Definition: types.h:34
uint16_t u16
16-bit unsigned integer.
Definition: types.h:20
u32 Result
Function error code result type.
Definition: types.h:44
int32_t s32
32-bit signed integer.
Definition: types.h:27
uint32_t u32
32-bit unsigned integer.
Definition: types.h:21