1
0
mirror of https://gitlab.os-k.eu/os-k-team/os-k.git synced 2023-08-25 14:03:10 +02:00
os-k/kaleid/include/base/limits.h

79 lines
2.8 KiB
C
Raw Normal View History

2019-01-21 15:00:04 +01:00
//----------------------------------------------------------------------------//
// GNU GPL OS/K //
// //
// Authors: spectral` //
// NeoX //
// //
// Desc: Kaleid type limits definitions //
//----------------------------------------------------------------------------//
#ifndef _KALBASE_LIMITS_H
#define _KALBASE_LIMITS_H
//------------------------------------------//
2019-02-06 14:07:38 +01:00
#define BYTE unsigned char
#define WORD unsigned short
#define DWORD unsigned int
#define QWORD unsigned long
2019-01-21 15:00:04 +01:00
2019-02-06 14:07:38 +01:00
#define CHAR_BIT 8
#define BITS_IN(T) (sizeof(T) * CHAR_BIT)
2019-01-21 15:00:04 +01:00
2019-02-06 14:07:38 +01:00
/* XXX find a generic way */
#define BYTES_TO_WORDS(B) ((B) >> 1)
#define BYTES_TO_DWORDS(B) ((B) >> 2)
#define BYTES_TO_QWORDS(B) ((B) >> 3)
#define WORDS_TO_BYTES(W) ((W) << 1)
#define WORDS_TO_DWORDS(W) ((W) >> 1)
#define WORDS_TO_QWORDS(W) ((W) >> 2)
#define DWORDS_TO_BYTES(D) ((D) << 2)
#define DWORDS_TO_WORDS(D) ((D) << 1)
#define DWORDS_TO_QWORDS(D) ((D) >> 1)
#define QWORDS_TO_BYTES(Q) ((Q) << 3)
#define QWORDS_TO_WORDS(Q) ((Q) << 2)
#define QWORDS_TO_DWORDS(Q) ((Q) << 1)
2019-01-21 15:00:04 +01:00
//------------------------------------------//
2019-02-06 14:07:38 +01:00
/* U/L suffixes on hex numbers look odd */
#define SCHAR_MAX ((signed char) 0x7F)
#define SHRT_MAX ((short) 0x7FFF)
#define INT_MAX ((int) 0x7FFFFFFF)
#define LONG_MAX ((long) 0x7FFFFFFFFFFFFFFFL)
#define UCHAR_MAX ((unsigned char) 0xFFU)
#define USHRT_MAX ((unsigned short) 0xFFFFU)
#define UINT_MAX ((unsigned int) 0xFFFFFFFFU)
#define ULONG_MAX ((unsigned long) 0xFFFFFFFFFFFFFFFFUL)
2019-01-21 15:00:04 +01:00
2019-02-06 14:07:38 +01:00
#define SCHAR_MIN ((signed char) -SCHAR_MAX - 1)
#define SHRT_MIN ((short) -SHRT_MAX - 1)
#define INT_MIN ((int) -INT_MAX - 1)
#define LONG_MIN ((long) -LONG_MAX - 1L)
2019-01-21 15:00:04 +01:00
2019-02-06 14:07:38 +01:00
#ifdef __CHAR_UNSIGNED__
2019-01-21 15:00:04 +01:00
# define CHAR_MIN ((char)0)
# define CHAR_MAX ((char)UCHAR_MAX)
2019-02-06 14:07:38 +01:00
#else
2019-01-21 15:00:04 +01:00
# define CHAR_MIN ((char)SCHAR_MIN)
# define CHAR_MAX ((char)SCHAR_MAX)
#endif
2019-02-06 14:07:38 +01:00
#define SSIZE_T_MIN LONG_MIN
#define SSIZE_T_MAX LONG_MAX
#define SIZE_T_MAX ULONG_MAX
2019-01-21 15:00:04 +01:00
#ifdef NEED_MORE_USELESS_DATA
# define UCHAR_MIN ((unsigned char)0)
# define USHRT_MIN ((unsigned short)0)
# define UINT_MIN ((unsigned int)0)
# define ULONG_MIN ((unsigned long)0)
# ifdef STILL_NEED_MORE_USELESS_DATA
# error "Not enough useless data!"
# endif
#endif
//------------------------------------------//
#endif