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/include/base/limits.h
2019-04-06 07:53:58 +02:00

94 lines
4.0 KiB
C

//----------------------------------------------------------------------------//
// GNU GPL OS/K //
// //
// Desc: Integer types limits and utilities //
// //
// //
// Copyright © 2018-2019 The OS/K Team //
// //
// This file is part of OS/K. //
// //
// OS/K is free software: you can redistribute it and/or modify //
// it under the terms of the GNU General Public License as published by //
// the Free Software Foundation, either version 3 of the License, or //
// any later version. //
// //
// OS/K is distributed in the hope that it will be useful, //
// but WITHOUT ANY WARRANTY//without even the implied warranty of //
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
// GNU General Public License for more details. //
// //
// You should have received a copy of the GNU General Public License //
// along with OS/K. If not, see <https://www.gnu.org/licenses/>. //
//----------------------------------------------------------------------------//
#ifndef _KALBASE_LIMITS_H
#define _KALBASE_LIMITS_H
//------------------------------------------//
#define BYTE unsigned char
#define WORD unsigned short
#define DWORD unsigned int
#define QWORD unsigned long
#define CHAR_BIT 8
#define BITS_IN(T) (sizeof(T) * CHAR_BIT)
/* 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)
//------------------------------------------//
/* 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)
#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)
#ifdef __CHAR_UNSIGNED__
# define CHAR_MIN ((char)0)
# define CHAR_MAX ((char)UCHAR_MAX)
#else
# define CHAR_MIN ((char)SCHAR_MIN)
# define CHAR_MAX ((char)SCHAR_MAX)
#endif
#define SSIZE_T_MIN LONG_MIN
#define SSIZE_T_MAX LONG_MAX
#define SIZE_T_MAX ULONG_MAX
#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