/** @file dk4types.h Data types for DK libraries. The dkChar data type is mapped to char on all non-Windows platforms, wchar_t on Windows. The dk4_c16_t and dk4_c32_t types are for 16 and 32 bit characters. The dk4_im_t and dk4_um_t are signed and unsigned integer types of largest size available on the system. All integer values can be cast to these types without loss. */ #ifndef DK4TYPES_H_INCLUDED /** Protection against multiple inclusion. */ #define DK4TYPES_H_INCLUDED 1 #ifndef DK4CONF_H_INCLUDED #include "dk4conf.h" #endif #ifndef STDIO_H_INCLUDED #include #define STDIO_H_INCLUDED 1 #endif #ifndef STDLIB_H_INCLUDED #include #define STDLIB_H_INCLUDED 1 #endif #if DK4_HAVE_SYS_TYPES_H #ifndef SYS_TYPES_H_INCLUDED #include #define SYS_TYPES_H_INCLUDED 1 #endif #endif #if DK4_HAVE_STDINT_H #ifndef STDINT_H_INCLUDED #if defined(__cplusplus) && (!defined(__STDC_LIMIT_MACROS)) /** Allow use of limit macros from stdint.h file. */ #define __STDC_LIMIT_MACROS 1 #endif #if defined(__cplusplus) && (!defined(__STDC_CONSTANT_MACROS)) /** Allow use of constant macros from stdint.h file. */ #define __STDC_CONSTANT_MACROS 1 #endif #include #define STDINT_H_INCLUDED 1 #endif #endif #if DK4_HAVE_INTTYPES_H #ifndef INTTYPES_H_INCLUDED #include #define INTTYPES_H_INCLUDED 1 #endif #endif #if DK4_HAVE_SIGNAL_H #ifndef SIGNAL_H_INCLUDED #include #define SIGNAL_H_INCLUDED 1 #endif #endif #if DK4_HAVE_WCHAR_H #ifndef WCHAR_H_INCLUDED #include #define WCHAR_H_INCLUDED 1 #endif #endif #if DK4_HAVE_FLOAT_H #ifndef FLOAT_H_INCLUDED #include #define FLOAT_H_INCLUDED 1 #endif #endif #ifdef _WIN32 /** 16 bit character. The dkChar type is mapped to wchar_t on Windows, char on all other systems. */ typedef wchar_t dkChar; /** Size of a dkChar. */ #define DK4_CHAR_SIZE 2 /** Generate dkChar literals. */ #define dkT(x) L ## x #else /* ifdef _WIN32 */ /** Simple 8 bit character. The dkChar type is mapped to wchar_t on Windows, char on all other systems. */ typedef char dkChar; /** Size of a dkChar. */ #define DK4_CHAR_SIZE 1 /** Generate dkChar literals. */ #define dkT(x) x #endif /* ifdef _WIN32 */ #if DK4_SIZEOF_SHORT >= 2 /** 16 bit character, UTF-16 encoded. */ typedef unsigned short dk4_c16_t; /** Notation for 16 bit values. */ #define dkC16(x) x ## U #else #if DK4_SIZEOF_INT >= 2 /** 16 bit character, UTF-16 encoded. */ typedef unsigned int dk4_c16_t; /** Notation for 16 bit values. */ #define dkC16(x) x ## U #else #if DK4_SIZEOF_LONG >= 2 /** 16 bit character, UTF-16 encoded. */ typedef unsigned long dk4_c16_t; /** Notation for 16 bit values. */ #define dkC16(x) x ## UL #else #error "No integer type long enough for 16 bits!" #endif #endif #endif #if DK4_SIZEOF_SHORT >= 4 /** 32 bit Unicode character. */ typedef unsigned short dk4_c32_t; /** 4 bytes type (double word). */ typedef unsigned short dk4_dword_t; /** Notation for 32 bit values. */ #define dkC32(x) x ## U #else #if DK4_SIZEOF_INT >= 4 /** 32 bit Unicode character. */ typedef unsigned int dk4_c32_t; /** 4 bytes type (double word). */ typedef unsigned int dk4_dword_t; /** Notation for 32 bit values. */ #define dkC32(x) x ## U #else #if DK4_SIZEOF_LONG >= 4 /** 32 bit Unicode character. */ typedef unsigned long dk4_c32_t; /** 4 bytes type (double word). */ typedef unsigned long dk4_dword_t; /** Notation for 32 bit values. */ #define dkC32(x) x ## UL #else #error "No integer type long enough for 32 bits!" #endif #endif #endif #if DK4_HAVE_INTMAX_T /** Maximum unsigned integer. */ typedef uintmax_t dk4_um_t; /** Maximum signed integer. */ typedef intmax_t dk4_im_t; #else #if DK4_HAVE_LONG_LONG /** Maximum unsigned integer. */ typedef unsigned long long dk4_um_t; /** Maximum signed integer. */ typedef long long dk4_im_t; #else /** Maximum unsigned integer. */ typedef unsigned long dk4_um_t; /** Maximum signed integer. */ typedef long dk4_im_t; #endif #endif #if DK4_HAVE_SIG_ATOMIC_T /** Atomic integer type. */ typedef sig_atomic_t dk4_sig_atomic_t; #else /** Atomic integer type. */ typedef char dk4_sig_atomic_t; #endif /** Protorype for signal handlers. */ typedef void dk4_sig_handler_t(int); #if DK4_HAVE_VOLATILE /** Use volatile keyword. */ #define DK4_VOLATILE volatile #else /** Volatile keyword not defined. */ #define DK4_VOLATILE /* not defined */ #endif #if !DK4_HAVE_UINT8_T /** 8 bit data type. */ typedef unsigned char uint8_t; #endif #if !DK4_HAVE_UINT16_T #if DK4_SIZEOF_SHORT >= 2 /** 16 bit data type. */ typedef unsigned short uint16_t; #else #if DK4_SIZEOF_INT >= 2 /** 16 bit data type. */ typedef unsigned int uint16_t; #else #if DK4_SIZEOF_LONG >= 2 /** 16 bit data type. */ typedef unsigned long uint16_t; #else #error "No data type found for uint16_t!" #endif #endif #endif #endif #if !DK4_HAVE_INT8_T /** 8 bit signed data type. */ typedef signed char int8_t; #endif #if !DK4_HAVE_INT16_t #if DK4_SIZEOF_SHORT >= 2 /** 16 bit signed data type. */ typedef short int16_t; #else #if DK4_SIZEOF_INT >= 2 /** 16 bit signed data type. */ typedef int int16_t; #else #if DK4_SIZEOF_LONG >= 2 /** 16 bit signed data type. */ typedef long int16_t; #else #error "No data type found for int16_t!" #endif #endif #endif #endif #if !DK4_HAVE_UINT32_T #if DK4_SIZEOF_SHORT >= 4 /** 32 bit data type. */ typedef unsigned short uint32_t; #else #if DK4_SIZEOF_INT >= 4 /** 32 bit data type. */ typedef unsigned int uint32_t; #else #if DK4_SIZEOF_LONG >= 4 /** 32 bit data type. */ typedef unsigned long uint32_t; #else #error "No data type found for uint32_t!" #endif #endif #endif #endif #if !DK4_HAVE_INT32_T #if DK4_SIZEOF_SHORT >= 4 /** 32 bit signed data type. */ typedef short int32_t; #else #if DK4_SIZEOF_INT >= 4 /** 32 bit signed data type. */ typedef int int32_t; #else #if DK4_SIZEOF_LONG >= 4 /** 32 bit signed data type. */ #define long int32_t; #else #error "No data type found for int32_t!" #endif #endif #endif #endif #ifndef DK4_U16_MAX /** Maximum value for 16 bit unsigned integer. */ #define DK4_U16_MAX ((uint16_t)(0xFFFFU)) #endif #ifndef DK4_I16_MAX /** Maximum value for 16 bit signed integer. */ #define DK4_I16_MAX ((int16_t)(0x7FFFU)) #endif #ifndef DK4_I16_MIN /** Minimum value for 16 bit signed integer. */ #define DK4_I16_MIN ((int16_t)(-0x7FFF - 1)) #endif #ifndef DK4_U32_MAX /** Maximum value for 32 bit unsigned integer. */ #define DK4_U32_MAX ((uint32_t)(0xFFFFFFFFUL)) #endif #ifndef DK4_I32_MAX /** Maximum value for 32 bit signed integer. */ #define DK4_I32_MAX ((int32_t)(0x7FFFFFFFL)) #endif #ifndef DK4_I32_MIN /** Minimum value for 32 bit signed integer. */ #define DK4_I32_MIN ((int32_t)(-0x7FFFFFFFL - 1L)) #endif #ifndef DK4_DBL_DIGITS #ifdef DBL_DECIMAL_DIG /** Number of digits to printf or scanf a double without precision loss. */ #define DK4_DBL_DIGITS (DBL_DECIMAL_DIG) #else #ifdef DECIMAL_DIG /** Number of digits to printf or scanf a double without precision loss. */ #define DK4_DBL_DIGITS (DECIMAL_DIG) #else #ifdef DBL_DIG /** Number of digits to printf or scanf a double without precision loss. */ #define DK4_DBL_DIGITS ((DBL_DIG) + 3) #else /** Number of digits to printf or scanf a double without precision loss. */ #define DK4_DBL_DIGITS 17 #endif #endif #endif #endif /** Pointer to const dkChar. */ typedef const dkChar *DK4_PCDKCHAR; /** Pointer to dkChar. */ typedef dkChar *DK4_PDKCHAR; /** Pointer to const character. */ typedef const char *DK4_PCCHAR; /** Pointer to character. */ typedef char *DK4_PCHAR; #endif /* ifndef DK4TYPES_H_INCLUDED */