Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(35)

Side by Side Diff: base/basictypes.h

Issue 117323010: Redefine (u)int{8,16,32} as (u)int{8,16,32}_t. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: delete fixme Created 6 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef BASE_BASICTYPES_H_ 5 #ifndef BASE_BASICTYPES_H_
6 #define BASE_BASICTYPES_H_ 6 #define BASE_BASICTYPES_H_
7 7
8 #include <limits.h> // So we can set the bounds of our types. 8 #include <limits.h> // So we can set the bounds of our types.
9 #include <stddef.h> // For size_t. 9 #include <stddef.h> // For size_t.
10 #include <stdint.h> // For intptr_t. 10 #include <stdint.h> // For intptr_t.
11 #include <string.h> // For memcpy. 11 #include <string.h> // For memcpy.
12 12
13 #include "base/compiler_specific.h" 13 #include "base/compiler_specific.h"
14 #include "base/port.h" // Types that only need exist on certain systems. 14 #include "base/port.h" // Types that only need exist on certain systems.
15 15
16 typedef signed char schar; 16 // TODO(vtl): We get conflicts with other definitions of |int8|/|uint8| if we
17 typedef signed char int8; 17 // try to define them as |int8_t|/|uint8_t|, at least on Windows.
18 typedef short int16; 18 #ifdef _MSC_VER
19 typedef int int32; 19 typedef signed char int8;
20 typedef unsigned char uint8;
21 #else
22 typedef int8_t int8;
23 typedef uint8_t uint8;
24 #endif
20 25
26 typedef int16_t int16;
27 typedef int32_t int32;
28 typedef uint16_t uint16;
29 typedef uint32_t uint32;
30
31 // TODO(vtl): Figure what's up with the 64-bit types. Can we just define them as
32 // |int64_t|/|uint64_t|?
21 // The NSPR system headers define 64-bit as |long| when possible, except on 33 // The NSPR system headers define 64-bit as |long| when possible, except on
22 // Mac OS X. In order to not have typedef mismatches, we do the same on LP64. 34 // Mac OS X. In order to not have typedef mismatches, we do the same on LP64.
23 // 35 //
24 // On Mac OS X, |long long| is used for 64-bit types for compatibility with 36 // On Mac OS X, |long long| is used for 64-bit types for compatibility with
25 // <inttypes.h> format macros even in the LP64 model. 37 // <inttypes.h> format macros even in the LP64 model.
26 #if defined(__LP64__) && !defined(OS_MACOSX) && !defined(OS_OPENBSD) 38 #if defined(__LP64__) && !defined(OS_MACOSX) && !defined(OS_OPENBSD)
27 typedef long int64; 39 typedef long int64;
28 #else
29 typedef long long int64;
30 #endif
31
32 // NOTE: It is DANGEROUS to compare signed with unsigned types in loop
33 // conditions and other conditional expressions, and it is DANGEROUS to
34 // compute object/allocation sizes, indices, and offsets with signed types.
35 // Integer overflow behavior for signed types is UNDEFINED in the C/C++
36 // standards, but is defined for unsigned types.
37 //
38 // Use the unsigned types if your variable represents a bit pattern (e.g. a
39 // hash value), object or allocation size, object count, offset,
40 // array/vector index, etc.
41 //
42 // Do NOT use 'unsigned' to express "this value should always be positive";
43 // use assertions for this.
44 //
45 // See the Chromium style guide for more information.
46 // https://sites.google.com/a/chromium.org/dev/developers/coding-style
47
48 typedef unsigned char uint8;
49 typedef unsigned short uint16;
50 typedef unsigned int uint32;
51
52 // See the comment above about NSPR and 64-bit.
53 #if defined(__LP64__) && !defined(OS_MACOSX) && !defined(OS_OPENBSD)
54 typedef unsigned long uint64; 40 typedef unsigned long uint64;
55 #else 41 #else
42 typedef long long int64;
56 typedef unsigned long long uint64; 43 typedef unsigned long long uint64;
57 #endif 44 #endif
58 45
59 // A type to represent a Unicode code-point value. As of Unicode 4.0, 46 // A type to represent a Unicode code-point value. As of Unicode 4.0,
60 // such values require up to 21 bits. 47 // such values require up to 21 bits.
61 // (For type-checking on pointers, make this explicitly signed, 48 // (For type-checking on pointers, make this explicitly signed,
62 // and it should always be the signed version of whatever int32 is.) 49 // and it should always be the signed version of whatever int32 is.)
63 typedef signed int char32; 50 // TODO(vtl): This is almost completely unused in Chromium. Delete it?
51 typedef signed int char32;
64 52
65 const uint8 kuint8max = (( uint8) 0xFF); 53 const uint8 kuint8max = (( uint8) 0xFF);
66 const uint16 kuint16max = ((uint16) 0xFFFF); 54 const uint16 kuint16max = ((uint16) 0xFFFF);
67 const uint32 kuint32max = ((uint32) 0xFFFFFFFF); 55 const uint32 kuint32max = ((uint32) 0xFFFFFFFF);
68 const uint64 kuint64max = ((uint64) GG_LONGLONG(0xFFFFFFFFFFFFFFFF)); 56 const uint64 kuint64max = ((uint64) GG_LONGLONG(0xFFFFFFFFFFFFFFFF));
69 const int8 kint8min = (( int8) 0x80); 57 const int8 kint8min = (( int8) 0x80);
70 const int8 kint8max = (( int8) 0x7F); 58 const int8 kint8max = (( int8) 0x7F);
71 const int16 kint16min = (( int16) 0x8000); 59 const int16 kint16min = (( int16) 0x8000);
72 const int16 kint16max = (( int16) 0x7FFF); 60 const int16 kint16max = (( int16) 0x7FFF);
73 const int32 kint32min = (( int32) 0x80000000); 61 const int32 kint32min = (( int32) 0x80000000);
(...skipping 290 matching lines...) Expand 10 before | Expand all | Expand 10 after
364 352
365 // Use these to declare and define a static local variable (static T;) so that 353 // Use these to declare and define a static local variable (static T;) so that
366 // it is leaked so that its destructors are not called at exit. If you need 354 // it is leaked so that its destructors are not called at exit. If you need
367 // thread-safe initialization, use base/lazy_instance.h instead. 355 // thread-safe initialization, use base/lazy_instance.h instead.
368 #define CR_DEFINE_STATIC_LOCAL(type, name, arguments) \ 356 #define CR_DEFINE_STATIC_LOCAL(type, name, arguments) \
369 static type& name = *new type arguments 357 static type& name = *new type arguments
370 358
371 } // base 359 } // base
372 360
373 #endif // BASE_BASICTYPES_H_ 361 #endif // BASE_BASICTYPES_H_
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698