Merge mozilla-central and tracemonkey. (a=blockers)
[mozilla-central.git] / js / src / jsstdint.h
blob446a87319ac052e6a568797a3d3b382c161d47e6
1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
2 * vim: set ts=8 sw=4 et tw=78:
4 * ***** BEGIN LICENSE BLOCK *****
5 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
7 * The contents of this file are subject to the Mozilla Public License Version
8 * 1.1 (the "License"); you may not use this file except in compliance with
9 * the License. You may obtain a copy of the License at
10 * http://www.mozilla.org/MPL/
12 * Software distributed under the License is distributed on an "AS IS" basis,
13 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
14 * for the specific language governing rights and limitations under the
15 * License.
17 * The Original Code is mozilla.org code.
19 * The Initial Developer of the Original Code is
20 * Jim Blandy
21 * Portions created by the Initial Developer are Copyright (C) 2008
22 * the Initial Developer. All Rights Reserved.
24 * Contributor(s):
26 * Alternatively, the contents of this file may be used under the terms of
27 * either of the GNU General Public License Version 2 or later (the "GPL"),
28 * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
29 * in which case the provisions of the GPL or the LGPL are applicable instead
30 * of those above. If you wish to allow use of your version of this file only
31 * under the terms of either the GPL or the LGPL, and not to allow others to
32 * use your version of this file under the terms of the MPL, indicate your
33 * decision by deleting the provisions above and replace them with the notice
34 * and other provisions required by the GPL or the LGPL. If you do not delete
35 * the provisions above, a recipient may use your version of this file under
36 * the terms of any one of the MPL, the GPL or the LGPL.
38 * ***** END LICENSE BLOCK ***** */
41 * This header provides definitions for the <stdint.h> types we use,
42 * even on systems that lack <stdint.h>.
44 * NOTE: This header should only be included in private SpiderMonkey
45 * code; public headers should use only the JS{Int,Uint}N types; see
46 * the comment for them in "jsinttypes.h".
48 * At the moment, these types are not widely used within SpiderMonkey;
49 * this file is meant to make existing uses portable, and to allow us
50 * to transition portably to using them more, if desired.
53 #ifndef jsstdint_h___
54 #define jsstdint_h___
56 #include "jsinttypes.h"
58 /* If we have a working stdint.h, then jsinttypes.h has already
59 defined the standard integer types. Otherwise, define the standard
60 names in terms of the 'JS' types. */
61 #if ! defined(JS_HAVE_STDINT_H) && \
62 ! defined(JS_SYS_TYPES_H_DEFINES_EXACT_SIZE_TYPES)
64 typedef JSInt8 int8_t;
65 typedef JSInt16 int16_t;
66 typedef JSInt32 int32_t;
67 typedef JSInt64 int64_t;
69 typedef JSUint8 uint8_t;
70 typedef JSUint16 uint16_t;
71 typedef JSUint32 uint32_t;
72 typedef JSUint64 uint64_t;
74 /* Suppress other, conflicting attempts to define stdint-bits. */
75 #define _STDINT_H
77 /* If JS_STDDEF_H_HAS_INTPTR_T or JS_CRTDEFS_H_HAS_INTPTR_T are
78 defined, then jsinttypes.h included the given header, which
79 introduced definitions for intptr_t and uintptr_t. Otherwise,
80 define the standard names in terms of the 'JS' types. */
81 #if !defined(JS_STDDEF_H_HAS_INTPTR_T) && !defined(JS_CRTDEFS_H_HAS_INTPTR_T)
82 typedef JSIntPtr intptr_t;
83 typedef JSUintPtr uintptr_t;
84 #endif
86 #if !defined(__cplusplus) || defined(__STDC_LIMIT_MACROS)
88 #define INT8_MAX 127
89 #define INT8_MIN (-INT8_MAX - 1)
90 #define INT16_MAX 32767
91 #define INT16_MIN (-INT16_MAX - 1)
92 #define INT32_MAX 2147483647
93 #define INT32_MIN (-INT32_MAX - 1)
94 #define INT64_MAX 9223372036854775807LL
95 #define INT64_MIN (-INT64_MAX - 1)
97 #define UINT8_MAX 255
98 #define UINT16_MAX 65535
99 #define UINT32_MAX 4294967295U
100 #define UINT64_MAX 18446744073709551615ULL
103 * These are technically wrong as they can't be used in the preprocessor, but
104 * we would require compiler assistance, and at the moment we don't need
105 * preprocessor-correctness.
107 #ifdef _MSC_VER
108 #undef SIZE_MAX
109 #endif
111 #define INTPTR_MAX ((intptr_t) (UINTPTR_MAX >> 1))
112 #define INTPTR_MIN (intptr_t(uintptr_t(INTPTR_MAX) + uintptr_t(1)))
113 #define UINTPTR_MAX ((uintptr_t) -1)
114 #define SIZE_MAX UINTPTR_MAX
115 #define PTRDIFF_MAX INTPTR_MAX
116 #define PTRDIFF_MIN INTPTR_MIN
118 #endif /* !defined(__cplusplus) || defined(__STDC_LIMIT_MACROS) */
120 #endif /* JS_HAVE_STDINT_H */
122 #endif /* jsstdint_h___ */