15d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// Copyright 2013 The Chromium Authors. All rights reserved. 25821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be 35821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// found in the LICENSE file. 45821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 55d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// This file contains definitions of our old basic integral types 65d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// ((u)int{8,16,32,64}) and further includes. I recommend that you use the C99 75d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// standard types instead, and include <stdint.h>/<stddef.h>/etc. as needed. 85d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// Note that the macros and macro-like constructs that were formerly defined in 95d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// this file are now available separately in base/macros.h. 105d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#ifndef BASE_BASICTYPES_H_ 125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define BASE_BASICTYPES_H_ 135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 145d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include <limits.h> // So we can set the bounds of our types. 155d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include <stddef.h> // For size_t. 165d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include <stdint.h> // For intptr_t. 175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 185d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "base/macros.h" 195d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "base/port.h" // Types that only need exist on certain systems. 205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 215d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// DEPRECATED: Please use (u)int{8,16,32,64}_t instead (and include <stdint.h>). 225d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)typedef int8_t int8; 235d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)typedef uint8_t uint8; 245d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)typedef int16_t int16; 255d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)typedef int32_t int32; 265d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)typedef uint16_t uint16; 275d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)typedef uint32_t uint32; 285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 295d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// TODO(vtl): Figure what's up with the 64-bit types. Can we just define them as 305d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// |int64_t|/|uint64_t|? 315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// The NSPR system headers define 64-bit as |long| when possible, except on 325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Mac OS X. In order to not have typedef mismatches, we do the same on LP64. 335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// 345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// On Mac OS X, |long long| is used for 64-bit types for compatibility with 355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// <inttypes.h> format macros even in the LP64 model. 365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#if defined(__LP64__) && !defined(OS_MACOSX) && !defined(OS_OPENBSD) 375d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)typedef long int64; 385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)typedef unsigned long uint64; 395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#else 405d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)typedef long long int64; 415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)typedef unsigned long long uint64; 425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#endif 435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 445d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// DEPRECATED: Please use std::numeric_limits (from <limits>) instead. 45116680a4aac90f2aa7413d9095a592090648e557Ben Murdochconst uint8 kuint8max = 0xFF; 46116680a4aac90f2aa7413d9095a592090648e557Ben Murdochconst uint16 kuint16max = 0xFFFF; 47116680a4aac90f2aa7413d9095a592090648e557Ben Murdochconst uint32 kuint32max = 0xFFFFFFFF; 48116680a4aac90f2aa7413d9095a592090648e557Ben Murdochconst uint64 kuint64max = 0xFFFFFFFFFFFFFFFFULL; 49116680a4aac90f2aa7413d9095a592090648e557Ben Murdochconst int8 kint8min = -0x7F - 1; 50116680a4aac90f2aa7413d9095a592090648e557Ben Murdochconst int8 kint8max = 0x7F; 51116680a4aac90f2aa7413d9095a592090648e557Ben Murdochconst int16 kint16min = -0x7FFF - 1; 52116680a4aac90f2aa7413d9095a592090648e557Ben Murdochconst int16 kint16max = 0x7FFF; 53116680a4aac90f2aa7413d9095a592090648e557Ben Murdochconst int32 kint32min = -0x7FFFFFFF - 1; 54116680a4aac90f2aa7413d9095a592090648e557Ben Murdochconst int32 kint32max = 0x7FFFFFFF; 55116680a4aac90f2aa7413d9095a592090648e557Ben Murdochconst int64 kint64min = -0x7FFFFFFFFFFFFFFFLL - 1; 56116680a4aac90f2aa7413d9095a592090648e557Ben Murdochconst int64 kint64max = 0x7FFFFFFFFFFFFFFFLL; 575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#endif // BASE_BASICTYPES_H_ 59