/** @file dk4numco.h Numeric constants. Typically the constants from limits.h and stdint.h are used. This file contains fallback definitions if the files are not available or some definitions are missing. */ #ifndef DK4NUMCO_H_INCLUDED /** Protection against multiple inclusion. */ #define DK4NUMCO_H_INCLUDED 1 #ifndef DK4CONF_H_INCLUDED #include "dk4conf.h" #endif #if DK4_HAVE_LIMITS_H #ifndef LIMITS_H_INCLUDED #include #define LIMITS_H_INCLUDED 1 #endif #endif #if DK4_HAVE_STDINT_H #ifndef STDINT_H_INCLUDED #if defined(__cplusplus) && (!defined(__STDC_LIMIT_MACROS)) /** For legacy compilers, use macros for integer limits. */ #define __STDC_LIMIT_MACROS 1 #endif #if defined(__cplusplus) && (!defined(__STDC_CONSTANT_MACROS)) /** For legacy compilers, use macros for constants. */ #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 /** Decision: Use fallback definitions for missing constants. On some systems the minimum/maximum constants are not defined. Here you can choose, whether the compiler should complain and bail out (0) or use a self-made definition (1). The default is to complain and bail out. */ #ifndef DK4_USE_FALLBACK_NUMERIC_LIMITS #define DK4_USE_FALLBACK_NUMERIC_LIMITS 0 #endif #ifndef SIZE_MAX #if !DK4_USE_FALLBACK_NUMERIC_LIMITS #error "SIZE_MAX undefined! See file dk4numco.h, line 10." #endif #if DK4_SIZEOF_SIZE_T > 2 #if DK4_SIZEOF_SIZE_T > 4 /** Maximum size_t value. */ #define SIZE_MAX 18446744073709551615ULL #else /** Maximum size_t value. */ #define SIZE_MAX 4294967295UL #endif #else /** Maximum size_t value. */ #define SIZE_MAX 65535U #endif #endif /* ifndef SIZE_MAX */ #ifndef SCHAR_MIN #if !DK4_USE_FALLBACK_NUMERIC_LIMITS #error "SCHAR_MIN undefined! See file dk4numco.h, line 10." #endif /** Minimum signed char value. */ #define SCHAR_MIN (-128) #endif /* ifndef SCHAR_MIN */ #ifndef SCHAR_MAX #if !DK4_USE_FALLBACK_NUMERIC_LIMITS #error "SCHAR_MAX undefined! See file dk4numco.h, line 10." #endif /** Maximum signed char value. */ #define SCHAR_MAX 127 #endif /* ifndef SCHAR_MAX */ #ifndef UCHAR_MAX #if !DK4_USE_FALLBACK_NUMERIC_LIMITS #error "UCHAR_MAX undefined! See file dk4numco.h, line 10." #endif /** Maximum unsigned char value. */ #define UCHAR_MAX 255 #endif /* ifndef UCHAR_MAX */ #ifndef SHRT_MIN #if !DK4_USE_FALLBACK_NUMERIC_LIMITS #error "SHRT_MIN undefined! See file dk4numco.h, line 10." #endif /** Minimum signed short value. */ #define SHRT_MIN (-32768) #endif /* ifndef SHRT_MIN */ #ifndef SHRT_MAX #if !DK4_USE_FALLBACK_NUMERIC_LIMITS #error "SHRT_MAX undefined! See file dk4numco.h, line 10." #endif /** Maximum signed short value. */ #define SHRT_MAX 32767 #endif /* ifndef SHRT_MAX */ #ifndef USHRT_MAX #if !DK4_USE_FALLBACK_NUMERIC_LIMITS #error "USHRT_MAX undefined! See file dk4numco.h, line 10." #endif /** Maximum unsigned short value. */ #define USHRT_MAX 65535 #endif /* ifndef USHRT_MAX */ #ifndef INT_MAX #if !DK4_USE_FALLBACK_NUMERIC_LIMITS #error "INT_MAX undefined! See file dk4numco.h, line 10." #endif #if DK4_SIZEOF_INT > 2 #if DK4_SIZEOF_INT > 4 #if DK4_SIZEOF_INT > 8 #error "Not prepared for such large int numbers!" #else /** Maximum signed int value. */ #define INT_MAX 9223372036854775807 #endif #else /** Maximum signed int value. */ #define INT_MAX 2147483647 #endif #else /** Maximum signed int value. */ #define INT_MAX 32767 #endif #endif /* ifndef INT_MAX */ #ifndef INT_MIN #if !DK4_USE_FALLBACK_NUMERIC_LIMITS #error "INT_MIN undefined! See file dk4numco.h, line 10." #endif /** Minimum signed int value. */ #define INT_MIN (-INT_MAX - 1) #endif /* ifndef INT_MIN */ #ifndef UINT_MAX #if !DK4_USE_FALLBACK_NUMERIC_LIMITS #error "LONG_MAX undefined! See file dk4numco.h, line 10." #endif #if DK4_SIZEOF_INT > 2 #if DK4_SIZEOF_INT > 4 #if DK4_SIZEOF_INT > 8 #error "Not prepared for such large int numbers!" #else /** Maximum unsigned int value. */ #define UINT_MAX 18446744073709551615U #endif #else /** Maximum unsigned int value. */ #define UINT_MAX 4294967295U #endif #else /** Maximum unsigned int value. */ #define UINT_MAX 65535U #endif #endif /* ifndef UINT_MAX */ #ifndef LONG_MAX #if !DK4_USE_FALLBACK_NUMERIC_LIMITS #error "LONG_MAX undefined! See file dk4numco.h, line 10." #endif #if DK4_SIZEOF_LONG > 2 #if DK4_SIZEOF_LONG > 4 #if DK4_SIZEOF_LONG > 8 #error "Not prepared for such large long numbers!" #else /** Maximum signed long value. */ #define LONG_MAX 9223372036854775807L #endif #else /** Maximum signed long value. */ #define LONG_MAX 2147483647L #endif #else /** Maximum signed long value. */ #define LONG_MAX 32767L #endif #endif /* ifndef LONG_MAX */ #ifndef LONG_MIN #if !DK4_USE_FALLBACK_NUMERIC_LIMITS #error "LONG_MIN undefined! See file dk4numco.h, line 10." #endif /** Minimum signed long value. */ #define LONG_MIN (-LONG_MAX - 1L) #endif /* ifndef LONG_MIN */ #ifndef ULONG_MAX #if !DK4_USE_FALLBACK_NUMERIC_LIMITS #error "ULONG_MAX undefined! See file dk4numco.h, line 10." #endif #if DK4_SIZEOF_LONG > 2 #if DK4_SIZEOF_LONG > 4 #if DK4_SIZEOF_LONG > 8 #error "Not prepared for such large long numbers!" #else /** Maximum unsigned long value. */ #define ULONG_MAX 18446744073709551615UL #endif #else /** Maximum unsigned long value. */ #define ULONG_MAX 4294967295UL #endif #else /** Maximum unsigned long value. */ #define ULONG_MAX 65535UL #endif #endif /* ifndef ULONG_MAX */ #if DK4_HAVE_LONG_LONG #ifndef LLONG_MAX #if !DK4_USE_FALLBACK_NUMERIC_LIMITS #error "LLONG_MAX undefined! See file dk4numco.h, line 10." #endif #if DK4_SIZEOF_LONG_LONG > 2 #if DK4_SIZEOF_LONG_LONG > 4 #if DK4_SIZEOF_LONG_LONG > 8 #error "Not prepared for such large long long numbers!" #else /** Maximum signed long long value. */ #define LLONG_MAX 9223372036854775807LL #endif #else /** Maximum signed long long value. */ #define LLONG_MAX 2147483647LL #endif #else /** Maximum signed long long value. */ #define LLONG_MAX 32767LL #endif #endif /* ifndef LLONG_MAX */ #ifndef LLONG_MIN #if !DK4_USE_FALLBACK_NUMERIC_LIMITS #error "LLONG_MIN undefined! See file dk4numco.h, line 10." #endif /** Minimum signed long long value. */ #define LLONG_MIN (-LLONG_MAX - 1LL) #endif /* ifndef LLONG_MIN */ #ifndef ULLONG_MAX #if !DK4_USE_FALLBACK_NUMERIC_LIMITS #error "ULLONG_MAX undefined! See file dk4numco.h, line 10." #endif #if DK4_SIZEOF_LONG_LONG > 2 #if DK4_SIZEOF_LONG_LONG > 4 #if DK4_SIZEOF_LONG_LONG > 8 #error "Not prepared for such large long long numbers!" #else /** Maximum unsigned long long value. */ #define ULLONG_MAX 18446744073709551615ULL #endif #else /** Maximum unsigned long long value. */ #define ULLONG_MAX 4294967295ULL #endif #else /** Maximum unsigned long long value. */ #define ULLONG_MAX 65535ULL #endif #endif /* ifndef ULLONG_MAX */ #endif /* if DK4_HAVE_LONG_LONG */ #if DK4_HAVE_INTMAX_T #ifndef INTMAX_MAX #if !DK4_USE_FALLBACK_NUMERIC_LIMITS #error "INTMAX_MAX undefined! See file dk4numco.h, line 10." #endif #if DK4_SIZEOF_INTMAX_T == DK4_SIZEOF_INT /** Maximum intmax_t value. */ #define INTMAX_MAX (INT_MAX) #else #if DK4_SIZEOF_INTMAX_T == DK4_SIZEOF_LONG /** Maximum intmax_t value. */ #define INTMAX_MAX (LONG_MAX) #else #if DK4_HAVE_LONG_LONG #if DK4_SIZEOF_INTMAX_T == DK4_SIZEOF_LONG_LONG /** Maximum intmax_t value. */ #define INTMAX_MAX (LLONG_MAX) #else #error "Not prepared for such large intmax_t numbers!" #endif #else #error "Not prepared for such large intmax_t numbers!" #endif #endif #endif #endif /* ifndef INTMAX_MAX */ #ifndef INTMAX_MIN #if !DK4_USE_FALLBACK_NUMERIC_LIMITS #error "INTMAX_MIN undefined! See file dk4numco.h, line 10." #endif /** Minimum intmax_t value. */ #define INTMAX_MIN (-(INTMAX_MAX) - (intmax_t)1) #endif /* ifndef INTMAX_MIN */ #ifndef UINTMAX_MAX #if !DK4_USE_FALLBACK_NUMERIC_LIMITS #error "UINTMAX_MAX undefined! See file dk4numco.h, line 10." #endif #if DK4_SIZEOF_INTMAX_T == DK4_SIZEOF_INT /** Maximum uintmax_t value. */ #define UINTMAX_MAX (UINT_MAX) #else #if DK4_SIZEOF_INTMAX_T == DK4_SIZEOF_LONG /** Maximum uintmax_t value. */ #define UINTMAX_MAX (ULONG_MAX) #else #if DK4_HAVE_LONG_LONG #if DK4_SIZEOF_INTMAX_T == DK4_SIZEOF_LONG_LONG /** Maximum uintmax_t value. */ #define UINTMAX_MAX (ULLONG_MAX) #else #error "Not prepared for such large uintmax_t numbers!" #endif #else #error "Not prepared for such large uintmax_t numbers!" #endif #endif #endif #endif /* ifndef UINTMAX_MAX */ #endif /* if DK4_HAVE_INTMAX_T */ #if DK4_HAVE_INTMAX_T /** Maximum dk4_um_t value. */ #define DK4_UM_MAX (UINTMAX_MAX) /** Maximum dk4_im_t value. */ #define DK4_IM_MAX (INTMAX_MAX) /** Minimum dk4_im_t value. */ #define DK4_IM_MIN (INTMAX_MIN) #else #if DK4_HAVE_LONG_LONG /** Maximum dk4_um_t value. */ #define DK4_UM_MAX (ULLONG_MAX) /** Maximum dk4_im_t value. */ #define DK4_IM_MAX (LLONG_MAX) /** Minimum dk4_im_t value. */ #define DK4_IM_MIN (LLONG_MIN) #else /** Maximum dk4_um_t value. */ #define DK4_UM_MAX (ULONG_MAX) /** Maximum dk4_im_t value. */ #define DK4_IM_MAX (LONG_MAX) /** Minimum dk4_im_t value. */ #define DK4_IM_MIN (LONG_MIN) #endif #endif #endif /* ifndef DK4NUMCO_H_INCLUDED */