Initial commit
This commit is contained in:
@@ -0,0 +1,232 @@
|
||||
/**
|
||||
* @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_TYPES_HEADER
|
||||
#define MALUNAL_TYPES_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 */
|
||||
|
||||
|
||||
/**
|
||||
* @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 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 constant 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 @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 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"
|
||||
);
|
||||
|
||||
|
||||
#endif /* MALUNAL_TYPES_HEADER */
|
||||
Reference in New Issue
Block a user