blob: 12d4c97f1c573abc4b3402dfbc91522ed01ef2e1 [file] [log] [blame]
viettrungluu@chromium.org429f53f2014-01-04 07:34:54 +09001// Copyright 2013 The Chromium Authors. All rights reserved.
license.botf003cfe2008-08-24 09:55:55 +09002// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
initial.commit3f4a7322008-07-27 06:49:38 +09004
viettrungluu@chromium.orgdb9d7b52014-01-09 06:38:30 +09005// This file contains definitions of our old basic integral types
6// ((u)int{8,16,32,64}) and further includes. I recommend that you use the C99
7// standard types instead, and include <stdint.h>/<stddef.h>/etc. as needed.
8// Note that the macros and macro-like constructs that were formerly defined in
9// this file are now available separately in base/macros.h.
10
mmentovai@google.com38cabad2008-08-13 10:17:18 +090011#ifndef BASE_BASICTYPES_H_
12#define BASE_BASICTYPES_H_
initial.commit3f4a7322008-07-27 06:49:38 +090013
viettrungluu@chromium.org429f53f2014-01-04 07:34:54 +090014#include <limits.h> // So we can set the bounds of our types.
15#include <stddef.h> // For size_t.
16#include <stdint.h> // For intptr_t.
initial.commit3f4a7322008-07-27 06:49:38 +090017
viettrungluu@chromium.orgdb9d7b52014-01-09 06:38:30 +090018#include "base/macros.h"
viettrungluu@chromium.org429f53f2014-01-04 07:34:54 +090019#include "base/port.h" // Types that only need exist on certain systems.
evanm@google.comb644fa82008-08-07 05:36:16 +090020
viettrungluu@chromium.orgdb9d7b52014-01-09 06:38:30 +090021// DEPRECATED: Please use (u)int{8,16,32,64}_t instead (and include <stdint.h>).
viettrungluu@chromium.orgf9b4a282014-01-07 04:35:56 +090022typedef int8_t int8;
23typedef uint8_t uint8;
viettrungluu@chromium.orgf9b4a282014-01-07 04:35:56 +090024typedef int16_t int16;
25typedef int32_t int32;
26typedef uint16_t uint16;
27typedef uint32_t uint32;
28
29// TODO(vtl): Figure what's up with the 64-bit types. Can we just define them as
30// |int64_t|/|uint64_t|?
mark@chromium.orgc684aba2011-03-23 08:28:59 +090031// The NSPR system headers define 64-bit as |long| when possible, except on
32// Mac OS X. In order to not have typedef mismatches, we do the same on LP64.
33//
34// On Mac OS X, |long long| is used for 64-bit types for compatibility with
35// <inttypes.h> format macros even in the LP64 model.
mark@chromium.org2e9e81c2011-10-13 13:23:22 +090036#if defined(__LP64__) && !defined(OS_MACOSX) && !defined(OS_OPENBSD)
viettrungluu@chromium.orgf9b4a282014-01-07 04:35:56 +090037typedef long int64;
deanm@chromium.orgdc8b4922009-07-28 06:17:23 +090038typedef unsigned long uint64;
39#else
viettrungluu@chromium.orgf9b4a282014-01-07 04:35:56 +090040typedef long long int64;
initial.commit3f4a7322008-07-27 06:49:38 +090041typedef unsigned long long uint64;
deanm@chromium.orgdc8b4922009-07-28 06:17:23 +090042#endif
initial.commit3f4a7322008-07-27 06:49:38 +090043
viettrungluu@chromium.orgdb9d7b52014-01-09 06:38:30 +090044// DEPRECATED: Please use std::numeric_limits (from <limits>) instead.
pkasting@chromium.org2962b2b2014-07-03 16:03:39 +090045const uint8 kuint8max = 0xFF;
46const uint16 kuint16max = 0xFFFF;
47const uint32 kuint32max = 0xFFFFFFFF;
48const uint64 kuint64max = 0xFFFFFFFFFFFFFFFFULL;
49const int8 kint8min = -0x7F - 1;
50const int8 kint8max = 0x7F;
51const int16 kint16min = -0x7FFF - 1;
52const int16 kint16max = 0x7FFF;
53const int32 kint32min = -0x7FFFFFFF - 1;
54const int32 kint32max = 0x7FFFFFFF;
55const int64 kint64min = -0x7FFFFFFFFFFFFFFFLL - 1;
56const int64 kint64max = 0x7FFFFFFFFFFFFFFFLL;
initial.commit3f4a7322008-07-27 06:49:38 +090057
mmentovai@google.com38cabad2008-08-13 10:17:18 +090058#endif // BASE_BASICTYPES_H_