292 lines
9.3 KiB
C
292 lines
9.3 KiB
C
/**
|
|
* @file types.h
|
|
* @brief Contains the definitions of various types used within malunal code
|
|
* bases and libraries.
|
|
* @author John Christman (sorakatadzuma@gmail.com)
|
|
* @copyright Malunal Studios, LLC.
|
|
*/
|
|
#ifndef MALUNAL_TYPE_HEADER
|
|
#define MALUNAL_TYPE_HEADER
|
|
|
|
#if __STDC_VERSION__ < 201112L
|
|
# error "This library requires C11 or later"
|
|
#endif
|
|
|
|
#if defined(__SIZEOF_POINTER__)
|
|
# define MALUNAL_POINTER_SIZE __SIZEOF_POINTER__
|
|
#elif defined(_MSC_VER)
|
|
# if defined(_M_X64) || defined(_M_ARM64)
|
|
# define MY_PTR_SIZE 8
|
|
# elif defined(_M_IX86) || defined(_M_ARM)
|
|
# define MY_PTR_SIZE 4
|
|
# else /* Unrecognized MSVC target */
|
|
# error "Unrecognized MSVC target architecture"
|
|
# endif /* MSVC compiler check */
|
|
#else /* Unrecognized compiler, no support */
|
|
# error "Unrecognized compiler - add support explicitly"
|
|
#endif /* Compiler dependent pointer size check */
|
|
|
|
/**
|
|
* @def null
|
|
* @brief Defines the value of the null pointer.
|
|
* @details This is here just in case it is not defined anywhere else, to make
|
|
* pointer usage easier.
|
|
*/
|
|
#ifndef null
|
|
#define null ((malunal_mptr_t)0)
|
|
#endif /* null */
|
|
|
|
/**
|
|
* @def true
|
|
* @brief Defines the value of the boolean true.
|
|
* @details This is here just in case it is not defined anywhere else, to make
|
|
* boolean usage easier.
|
|
*/
|
|
#ifndef true
|
|
#define true 1
|
|
#endif /* true */
|
|
|
|
/**
|
|
* @def false
|
|
* @brief Defines the value of the boolean false.
|
|
* @details This is here just in case it is not defined anywhere else, to make
|
|
* boolean usage easier.
|
|
*/
|
|
#ifndef false
|
|
#define false 0
|
|
#endif /* false */
|
|
|
|
|
|
/**
|
|
* @brief Our own definition of @c void.
|
|
* @details This is provided, like all of the types in this header, to meet
|
|
* modern standards and to exist specifically to match how we name
|
|
* many of our other types.
|
|
*/
|
|
typedef void malunal_void_t;
|
|
|
|
/**
|
|
* @brief Our own definition of a mutable pointer.
|
|
* @details This is provided, like all of the types in this header, to meet
|
|
* modern standards and to exist specifically to match how we name
|
|
* many of our other types.
|
|
*/
|
|
typedef void* malunal_mptr_t;
|
|
|
|
/**
|
|
* @brief Our own definition of an immutable pointer.
|
|
* @details This is provided, like all of the types in this header, to meet
|
|
* modern standards and to exist specifically to match how we name
|
|
* many of our other types.
|
|
*/
|
|
typedef const void* malunal_iptr_t;
|
|
|
|
/**
|
|
* @brief Our own definition of @c bool.
|
|
* @details This is provided, like all of the types in this header, to meet
|
|
* modern standards and to exist specifically to match how we name
|
|
* many of our other types.
|
|
*/
|
|
typedef _Bool malunal_bool_t;
|
|
|
|
/**
|
|
* @brief Our own definition of @c char.
|
|
* @details This is provided, like all of the types in this header, to meet
|
|
* modern standards and to exist specifically to match how we name
|
|
* many of our other types.
|
|
*/
|
|
typedef char malunal_char_t;
|
|
|
|
/**
|
|
* @brief Our own definition of a mutable string.
|
|
* @details This is provided, like all of the types in this header, to meet
|
|
* modern standards and to exist specifically to match how we name
|
|
* many of our other types.
|
|
*/
|
|
typedef char* malunal_str_t;
|
|
|
|
/**
|
|
* @brief Our own definition of a immutable string.
|
|
* @details This is provided, like all of the types in this header, to meet
|
|
* modern standards and to exist specifically to match how we name
|
|
* many of our other types.
|
|
*/
|
|
typedef const char* malunal_cstr_t;
|
|
|
|
/**
|
|
* @brief Our own definition of a single precision floting point number.
|
|
* @details This is provided, like all of the types in this header, to meet
|
|
* modern standards and to exist specifically to match how we name
|
|
* many of our other types.
|
|
*/
|
|
typedef float malunal_single_t;
|
|
|
|
/**
|
|
* @brief Our own definition of a double precision floting point number.
|
|
* @details This is provided, like all of the types in this header, to meet
|
|
* modern standards and to exist specifically to match how we name
|
|
* many of our other types.
|
|
*/
|
|
typedef double malunal_double_t;
|
|
|
|
/**
|
|
* @brief Our own definition of an 8-bit signed integer.
|
|
* @details This is provided, like all of the types in this header, to meet
|
|
* modern standards and to exist specifically to match how we name
|
|
* many of our other types.
|
|
*/
|
|
typedef signed char malunal_int8_t;
|
|
|
|
/**
|
|
* @brief Our own definition of an 16-bit signed integer.
|
|
* @details This is provided, like all of the types in this header, to meet
|
|
* modern standards and to exist specifically to match how we name
|
|
* many of our other types.
|
|
*/
|
|
typedef signed short malunal_int16_t;
|
|
|
|
/**
|
|
* @brief Our own definition of an 32-bit signed integer.
|
|
* @details This is provided, like all of the types in this header, to meet
|
|
* modern standards and to exist specifically to match how we name
|
|
* many of our other types.
|
|
*/
|
|
typedef signed int malunal_int32_t;
|
|
|
|
/**
|
|
* @brief Our own definition of an 8-bit unsigned integer.
|
|
* @details This is provided, like all of the types in this header, to meet
|
|
* modern standards and to exist specifically to match how we name
|
|
* many of our other types.
|
|
*/
|
|
typedef unsigned char malunal_uint8_t;
|
|
|
|
/**
|
|
* @brief Our own definition of an 16-bit unsigned integer.
|
|
* @details This is provided, like all of the types in this header, to meet
|
|
* modern standards and to exist specifically to match how we name
|
|
* many of our other types.
|
|
*/
|
|
typedef unsigned short malunal_uint16_t;
|
|
|
|
/**
|
|
* @brief Our own definition of an 32-bit unsigned integer.
|
|
* @details This is provided, like all of the types in this header, to meet
|
|
* modern standards and to exist specifically to match how we name
|
|
* many of our other types.
|
|
*/
|
|
typedef unsigned int malunal_uint32_t;
|
|
|
|
|
|
/**
|
|
* @typedef malunal_int64_t
|
|
* @brief Our own definition of an 64-bit signed integer.
|
|
* @details This is provided, like all of the types in this header, to meet
|
|
* modern standards and to exist specifically to match how we name
|
|
* many of our other types.
|
|
*/
|
|
/**
|
|
* @typedef malunal_uint64_t
|
|
* @brief Our own definition of an 64-bit unsigned integer.
|
|
* @details This is provided, like all of the types in this header, to meet
|
|
* modern standards and to exist specifically to match how we name
|
|
* many of our other types.
|
|
*/
|
|
#if defined(_MSC_VER)
|
|
typedef signed __int64 malunal_int64_t;
|
|
typedef unsigned __int64 malunal_uint64_t;
|
|
#else
|
|
typedef signed long long malunal_int64_t;
|
|
typedef unsigned long long malunal_uint64_t;
|
|
#endif /* Compiler specific. */
|
|
|
|
|
|
/**
|
|
* @typedef malunal_ptrdiff_t
|
|
* @brief Our own definition of an 64-bit pointer difference.
|
|
* @details This is provided, like all of the types in this header, to meet
|
|
* modern standards and to exist specifically to match how we name
|
|
* many of our other types.
|
|
*/
|
|
/**
|
|
* @typedef malunal_intptr_t
|
|
* @brief Our own definition of an 64-bit signed integer pointer.
|
|
* @details This is provided, like all of the types in this header, to meet
|
|
* modern standards and to exist specifically to match how we name
|
|
* many of our other types.
|
|
*/
|
|
/**
|
|
* @typedef malunal_size_t
|
|
* @brief Our own definition of an 64-bit unsigned integer.
|
|
* @details This is provided, like all of the types in this header, to meet
|
|
* modern standards and to exist specifically to match how we name
|
|
* many of our other types.
|
|
*/
|
|
/**
|
|
* @typedef malunal_uintptr_t
|
|
* @brief Our own definition of an 64-bit unsigned integer pointer.
|
|
* @details This is provided, like all of the types in this header, to meet
|
|
* modern standards and to exist specifically to match how we name
|
|
* many of our other types.
|
|
*/
|
|
#if MALUNAL_POINTER_SIZE == 8
|
|
typedef malunal_int64_t malunal_ptrdiff_t;
|
|
typedef malunal_int64_t malunal_intptr_t;
|
|
typedef malunal_uint64_t malunal_size_t;
|
|
typedef malunal_uint64_t malunal_uintptr_t;
|
|
#elif MALUNAL_POINTER_SIZE == 4
|
|
typedef malunal_int32_t malunal_ptrdiff_t;
|
|
typedef malunal_int32_t malunal_intptr_t;
|
|
typedef malunal_uint32_t malunal_size_t;
|
|
typedef malunal_uint32_t malunal_uintptr_t;
|
|
#else
|
|
# error "Unsupported pointer size"
|
|
#endif
|
|
|
|
|
|
_Static_assert(
|
|
sizeof(malunal_int8_t) == 1,
|
|
"malunal_int8_t must be 1 byte"
|
|
);
|
|
|
|
_Static_assert(
|
|
sizeof(malunal_int16_t) == 2,
|
|
"malunal_int16_t must be 2 bytes"
|
|
);
|
|
|
|
_Static_assert(
|
|
sizeof(malunal_int32_t) == 4,
|
|
"malunal_int32_t must be 4 bytes"
|
|
);
|
|
|
|
_Static_assert(
|
|
sizeof(malunal_int64_t) == 8,
|
|
"malunal_int64_t must be 8 bytes"
|
|
);
|
|
|
|
_Static_assert(
|
|
sizeof(malunal_size_t) == sizeof(void*),
|
|
"malunal_size_t must match pointer width"
|
|
);
|
|
|
|
_Static_assert(
|
|
sizeof(malunal_uintptr_t) == sizeof(void*),
|
|
"malunal_uintptr_t must match pointer width"
|
|
);
|
|
|
|
/**
|
|
* @def define_struct
|
|
* @brief Defines a structure and its pointer types.
|
|
* @details This simplifies the way we typically define our structures, in which
|
|
* we define the structure itself and type definitions for the mutable
|
|
* and immutable pointers to that structure.
|
|
* @param name The name of the structure.
|
|
*/
|
|
#define define_struct(name) \
|
|
typedef struct name name##_t; \
|
|
typedef name##_t* name##_mptr_t; \
|
|
typedef const name##_t* name##_iptr_t; \
|
|
struct name
|
|
|
|
#endif /* MALUNAL_TYPES_HEADER */
|