Mercurial > hg > th-libs
view th_types.h @ 320:0362ea9872f0
Some work on sign handling.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Tue, 23 Feb 2016 01:42:34 +0200 |
parents | 0078dc5f6260 |
children | 6e6c8c4fc210 |
line wrap: on
line source
/* * Type definations * Programmed and designed by Matti 'ccr' Hamalainen * (C) Copyright 2002-2015 Tecnic Software productions (TNSP) * * Please read file 'COPYING' for information on license and distribution. */ /* If your code uses "config.h", you need to #include * it before including this header. */ #ifndef _TH_TYPES_H #define _TH_TYPES_H // Check for standard headers #ifdef HAVE_STDINT_H # include <stdint.h> # ifndef HAVE_INT_TYPES # define HAVE_INT_TYPES 1 # endif // Check for arch bitness # if UINTPTR_MAX == 0xffffffff # define TH_ARCH 32 # elif UINTPTR_MAX == 0xffffffffffffffff # define TH_ARCH 64 # endif #endif #ifdef HAVE_SYS_TYPES_H # include <sys/types.h> # ifndef HAVE_INT_TYPES # define HAVE_INT_TYPES 1 # endif #endif #if !defined(TH_ARCH) # if defined(__LP64__) || defined(_LP64) # define TH_ARCH 64 # else # define TH_ARCH 32 # endif #endif #if !defined(TH_ARCH) && (defined(__WIN64) || defined(_WIN64)) # define TH_ARCH 64 #endif #if !defined(TH_ARCH) && (defined(__WIN32) || defined(_WIN32)) # define TH_ARCH 32 #endif // Do we have a valid arch? // If so, set some printf specifiers #if TH_ARCH == 32 # define TH_ARCH_32BIT 1 # define TH_PRIu32 "u" # define TH_PRId32 "d" # define TH_PRIx32 "x" # define TH_PRIu64 "llu" # define TH_PRId64 "lld" # define TH_PRIx64 "llx" # define TH_PRIu_SIZE_T "u" # define TH_PRId_SSIZE_T "d" # define TH_PRIx_SIZE_T "x" # ifndef TH_PTRSIZE # define TH_PTRSIZE 32 # endif # ifndef UINTPTR_MAX # define UINTPTR_MAX 0xffffffff # endif #elif TH_ARCH == 64 # define TH_ARCH_64BIT 1 # define TH_PRIu32 "u" # define TH_PRId32 "d" # define TH_PRIx32 "x" # define TH_PRIu64 "lu" # define TH_PRId64 "ld" # define TH_PRIx64 "lx" # define TH_PRIu_SIZE_T "lu" # define TH_PRId_SSIZE_T "ld" # define TH_PRIx_SIZE_T "lx" # ifndef TH_PTRSIZE # define TH_PTRSIZE 64 # endif # ifndef UINTPTR_MAX # define UINTPTR_MAX 0xffffffffffffffff # endif #else # error Could not determine architecture (32/64bit), please define TH_ARCH=32 or 64 #endif // Shorthand types typedef unsigned long int ulint_t; typedef signed long int lint_t; #ifndef HAVE_UINT_T // BOOST defines uint_t at least typedef unsigned int uint_t; #endif /* Default assumptions for these types should be ok for most 32bit platforms... * feel free to define TH_TYPE_* if necessary to remedy */ #ifdef TH_TYPE_I8 typedef unsigned TH_TYPE_I8 uint8_t; // 8 bits, unsigned typedef signed TH_TYPE_I8 int8_t; // 8 bits, signed #elif !defined(HAVE_INT_TYPES) typedef unsigned char uint8_t; typedef signed char int8_t; #endif #ifdef TH_TYPE_I16 typedef unsigned TH_TYPE_I16 uint16_t; // 16 bits, unsigned == 2 BYTEs typedef signed TH_TYPE_I16 int16_t; // 16 bits, signed #elif !defined(HAVE_INT_TYPES) typedef unsigned short int uint16_t; typedef signed short int int16_t; #endif #ifdef TH_TYPE_I32 typedef unsigned TH_TYPE_I32 uint32_t; // 32 bits, unsigned == 4 BYTES == 2 WORDs typedef signed TH_TYPE_I32 int32_t; // 32 bits, signed #elif !defined(HAVE_INT_TYPES) typedef unsigned int uint32_t; typedef signed int int32_t; #endif #ifdef TH_TYPE_I64 typedef unsigned TH_TYPE_I64 uint64_t; // 64 bits, unsigned == 8 BYTES == 2 DWORDs typedef signed TH_TYPE_I64 int64_t; // 64 bits, signed #elif !defined(HAVE_INT_TYPES) typedef unsigned long long uint64_t; typedef signed long long int64_t; #endif /* This is the character type used in all string-related routines of * th_libs. Currently it is set to be equivalent of basetype "char", * but under some platforms it may be necessary to use * "unsigned char" instead. * * Also in future this type may be changed to hold 32-bit UNICODE */ typedef char char_t; /* Define a boolean type */ #if !defined(FALSE) && !defined(TRUE) && !defined(BOOL) typedef enum { FALSE = 0, TRUE = 1 } BOOL; #endif #ifndef BOOL # ifdef bool # define BOOL bool # else # define BOOL int # endif #endif #endif // _TH_TYPES_H