summary refs log tree commit diff
path: root/src/Common/Sizes.hpp
blob: 036c98bbed2b52e363868b29a9d4ff8d6c6baadd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#pragma once

#include <cstdint>
#include <sys/types.h>

using I8 = int8_t;
using U8 = uint8_t;

using I16 = int16_t;
using U16 = uint16_t;

using I32 = int32_t;
using U32 = uint32_t;

using I64 = int64_t;
using U64 = uint64_t;

using ISize = ssize_t;
using USize = size_t;

using F32 = float;
using F64 = double;

using Bool = bool;

using Char = char;

using UInt = USize;
using Int = ISize;
using Real = F64;

#define ASSERT_SIZE(type, bytes) \
    static_assert(sizeof(type) == (bytes), "Type '" #type "' should be exactly " #bytes " bytes.")

ASSERT_SIZE(I8, 1);
ASSERT_SIZE(U8, 1);
ASSERT_SIZE(I16, 2);
ASSERT_SIZE(U16, 2);
ASSERT_SIZE(I32, 4);
ASSERT_SIZE(U32, 4);
ASSERT_SIZE(I64, 8);
ASSERT_SIZE(U64, 8);

ASSERT_SIZE(F32, 4);
ASSERT_SIZE(F64, 8);

ASSERT_SIZE(Bool, 1);

// MinGW doesn't define uint that I like to use
// in template definitions, so we need to define it here.

#ifdef __MINGW32__

#define uint uint32_t

#endif