clang API Documentation

limits.h
Go to the documentation of this file.
00001 /*===---- limits.h - Standard header for integer sizes --------------------===*\
00002  *
00003  * Copyright (c) 2009 Chris Lattner
00004  *
00005  * Permission is hereby granted, free of charge, to any person obtaining a copy
00006  * of this software and associated documentation files (the "Software"), to deal
00007  * in the Software without restriction, including without limitation the rights
00008  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
00009  * copies of the Software, and to permit persons to whom the Software is
00010  * furnished to do so, subject to the following conditions:
00011  *
00012  * The above copyright notice and this permission notice shall be included in
00013  * all copies or substantial portions of the Software.
00014  *
00015  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
00016  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
00017  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
00018  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
00019  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
00020  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
00021  * THE SOFTWARE.
00022  *
00023 \*===----------------------------------------------------------------------===*/
00024 
00025 #ifndef __CLANG_LIMITS_H
00026 #define __CLANG_LIMITS_H
00027 
00028 /* The system's limits.h may, in turn, try to #include_next GCC's limits.h.
00029    Avert this #include_next madness. */
00030 #if defined __GNUC__ && !defined _GCC_LIMITS_H_
00031 #define _GCC_LIMITS_H_
00032 #endif
00033 
00034 /* System headers include a number of constants from POSIX in <limits.h>.
00035    Include it if we're hosted. */
00036 #if __STDC_HOSTED__ && __has_include_next(<limits.h>)
00037 #include_next <limits.h>
00038 #endif
00039 
00040 /* Many system headers try to "help us out" by defining these.  No really, we
00041    know how big each datatype is. */
00042 #undef  SCHAR_MIN
00043 #undef  SCHAR_MAX
00044 #undef  UCHAR_MAX
00045 #undef  SHRT_MIN
00046 #undef  SHRT_MAX
00047 #undef  USHRT_MAX
00048 #undef  INT_MIN
00049 #undef  INT_MAX
00050 #undef  UINT_MAX
00051 #undef  LONG_MIN
00052 #undef  LONG_MAX
00053 #undef  ULONG_MAX
00054 
00055 #undef  CHAR_BIT
00056 #undef  CHAR_MIN
00057 #undef  CHAR_MAX
00058 
00059 /* C90/99 5.2.4.2.1 */
00060 #define SCHAR_MAX __SCHAR_MAX__
00061 #define SHRT_MAX  __SHRT_MAX__
00062 #define INT_MAX   __INT_MAX__
00063 #define LONG_MAX  __LONG_MAX__
00064 
00065 #define SCHAR_MIN (-__SCHAR_MAX__-1)
00066 #define SHRT_MIN  (-__SHRT_MAX__ -1)
00067 #define INT_MIN   (-__INT_MAX__  -1)
00068 #define LONG_MIN  (-__LONG_MAX__ -1L)
00069 
00070 #define UCHAR_MAX (__SCHAR_MAX__*2  +1)
00071 #define USHRT_MAX (__SHRT_MAX__ *2  +1)
00072 #define UINT_MAX  (__INT_MAX__  *2U +1U)
00073 #define ULONG_MAX (__LONG_MAX__ *2UL+1UL)
00074 
00075 #ifndef MB_LEN_MAX
00076 #define MB_LEN_MAX 1
00077 #endif
00078 
00079 #define CHAR_BIT  __CHAR_BIT__
00080 
00081 #ifdef __CHAR_UNSIGNED__  /* -funsigned-char */
00082 #define CHAR_MIN 0
00083 #define CHAR_MAX UCHAR_MAX
00084 #else
00085 #define CHAR_MIN SCHAR_MIN
00086 #define CHAR_MAX __SCHAR_MAX__
00087 #endif
00088 
00089 /* C99 5.2.4.2.1: Added long long.
00090    C++11 18.3.3.2: same contents as the Standard C Library header <limits.h>.
00091  */
00092 #if __STDC_VERSION__ >= 199901L || __cplusplus >= 201103L
00093 
00094 #undef  LLONG_MIN
00095 #undef  LLONG_MAX
00096 #undef  ULLONG_MAX
00097 
00098 #define LLONG_MAX  __LONG_LONG_MAX__
00099 #define LLONG_MIN  (-__LONG_LONG_MAX__-1LL)
00100 #define ULLONG_MAX (__LONG_LONG_MAX__*2ULL+1ULL)
00101 #endif
00102 
00103 /* LONG_LONG_MIN/LONG_LONG_MAX/ULONG_LONG_MAX are a GNU extension.  It's too bad
00104    that we don't have something like #pragma poison that could be used to
00105    deprecate a macro - the code should just use LLONG_MAX and friends.
00106  */
00107 #if defined(__GNU_LIBRARY__) ? defined(__USE_GNU) : !defined(__STRICT_ANSI__)
00108 
00109 #undef   LONG_LONG_MIN
00110 #undef   LONG_LONG_MAX
00111 #undef   ULONG_LONG_MAX
00112 
00113 #define LONG_LONG_MAX  __LONG_LONG_MAX__
00114 #define LONG_LONG_MIN  (-__LONG_LONG_MAX__-1LL)
00115 #define ULONG_LONG_MAX (__LONG_LONG_MAX__*2ULL+1ULL)
00116 #endif
00117 
00118 #endif /* __CLANG_LIMITS_H */