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__ && \
00037     defined(__has_include_next) && __has_include_next(<limits.h>)
00038 #include_next <limits.h>
00039 #endif
00040 
00041 /* Many system headers try to "help us out" by defining these.  No really, we
00042    know how big each datatype is. */
00043 #undef  SCHAR_MIN
00044 #undef  SCHAR_MAX
00045 #undef  UCHAR_MAX
00046 #undef  SHRT_MIN
00047 #undef  SHRT_MAX
00048 #undef  USHRT_MAX
00049 #undef  INT_MIN
00050 #undef  INT_MAX
00051 #undef  UINT_MAX
00052 #undef  LONG_MIN
00053 #undef  LONG_MAX
00054 #undef  ULONG_MAX
00055 
00056 #undef  CHAR_BIT
00057 #undef  CHAR_MIN
00058 #undef  CHAR_MAX
00059 
00060 /* C90/99 5.2.4.2.1 */
00061 #define SCHAR_MAX __SCHAR_MAX__
00062 #define SHRT_MAX  __SHRT_MAX__
00063 #define INT_MAX   __INT_MAX__
00064 #define LONG_MAX  __LONG_MAX__
00065 
00066 #define SCHAR_MIN (-__SCHAR_MAX__-1)
00067 #define SHRT_MIN  (-__SHRT_MAX__ -1)
00068 #define INT_MIN   (-__INT_MAX__  -1)
00069 #define LONG_MIN  (-__LONG_MAX__ -1L)
00070 
00071 #define UCHAR_MAX (__SCHAR_MAX__*2  +1)
00072 #define USHRT_MAX (__SHRT_MAX__ *2  +1)
00073 #define UINT_MAX  (__INT_MAX__  *2U +1U)
00074 #define ULONG_MAX (__LONG_MAX__ *2UL+1UL)
00075 
00076 #ifndef MB_LEN_MAX
00077 #define MB_LEN_MAX 1
00078 #endif
00079 
00080 #define CHAR_BIT  __CHAR_BIT__
00081 
00082 #ifdef __CHAR_UNSIGNED__  /* -funsigned-char */
00083 #define CHAR_MIN 0
00084 #define CHAR_MAX UCHAR_MAX
00085 #else
00086 #define CHAR_MIN SCHAR_MIN
00087 #define CHAR_MAX __SCHAR_MAX__
00088 #endif
00089 
00090 /* C99 5.2.4.2.1: Added long long. */
00091 #if __STDC_VERSION__ >= 199901
00092 
00093 #undef  LLONG_MIN
00094 #undef  LLONG_MAX
00095 #undef  ULLONG_MAX
00096 
00097 #define LLONG_MAX  __LONG_LONG_MAX__
00098 #define LLONG_MIN  (-__LONG_LONG_MAX__-1LL)
00099 #define ULLONG_MAX (__LONG_LONG_MAX__*2ULL+1ULL)
00100 #endif
00101 
00102 /* LONG_LONG_MIN/LONG_LONG_MAX/ULONG_LONG_MAX are a GNU extension.  It's too bad
00103    that we don't have something like #pragma poison that could be used to
00104    deprecate a macro - the code should just use LLONG_MAX and friends.
00105  */
00106 #if defined(__GNU_LIBRARY__) ? defined(__USE_GNU) : !defined(__STRICT_ANSI__)
00107 
00108 #undef   LONG_LONG_MIN
00109 #undef   LONG_LONG_MAX
00110 #undef   ULONG_LONG_MAX
00111 
00112 #define LONG_LONG_MAX  __LONG_LONG_MAX__
00113 #define LONG_LONG_MIN  (-__LONG_LONG_MAX__-1LL)
00114 #define ULONG_LONG_MAX (__LONG_LONG_MAX__*2ULL+1ULL)
00115 #endif
00116 
00117 #endif /* __CLANG_LIMITS_H */