basictypes.h revision 5d1f7b1de12d16ceb2c938c56701a3e8bfa558f7
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. 455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)const uint8 kuint8max = (( uint8) 0xFF); 465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)const uint16 kuint16max = ((uint16) 0xFFFF); 475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)const uint32 kuint32max = ((uint32) 0xFFFFFFFF); 485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)const uint64 kuint64max = ((uint64) GG_LONGLONG(0xFFFFFFFFFFFFFFFF)); 495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)const int8 kint8min = (( int8) 0x80); 505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)const int8 kint8max = (( int8) 0x7F); 515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)const int16 kint16min = (( int16) 0x8000); 525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)const int16 kint16max = (( int16) 0x7FFF); 535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)const int32 kint32min = (( int32) 0x80000000); 545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)const int32 kint32max = (( int32) 0x7FFFFFFF); 555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)const int64 kint64min = (( int64) GG_LONGLONG(0x8000000000000000)); 565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)const int64 kint64max = (( int64) GG_LONGLONG(0x7FFFFFFFFFFFFFFF)); 575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#endif // BASE_BASICTYPES_H_ 59