RavEngine
Loading...
Searching...
No Matches
integral_types.h
1/*
2Copyright 2018 Google Inc. All Rights Reserved.
3
4Licensed under the Apache License, Version 2.0 (the "License");
5you may not use this file except in compliance with the License.
6You may obtain a copy of the License at
7
8 http://www.apache.org/licenses/LICENSE-2.0
9
10Unless required by applicable law or agreed to in writing, software
11distributed under the License is distributed on an "AS-IS" BASIS,
12WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13See the License for the specific language governing permissions and
14limitations under the License.
15*/
16
17// Copyright 2015 Google Inc. All Rights Reserved.
18//
19// Licensed under the Apache License, Version 2.0 (the "License");
20// you may not use this file except in compliance with the License.
21// You may obtain a copy of the License at
22//
23// http://www.apache.org/licenses/LICENSE-2.0
24//
25// Unless required by applicable law or agreed to in writing, software
26// distributed under the License is distributed on an "AS IS" BASIS,
27// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
28// See the License for the specific language governing permissions and
29// limitations under the License.
30//
31// Basic integer type definitions for various platforms
32
33#ifndef BASE_INTEGRAL_TYPES_H_
34#define BASE_INTEGRAL_TYPES_H_
35
36// Standard typedefs
37typedef signed char schar;
38typedef signed char int8;
39typedef short int16;
40typedef int int32;
41#ifdef _MSC_VER
42typedef __int64 int64;
43#else
44typedef long long int64;
45#endif /* _MSC_VER */
46
47// NOTE: unsigned types are DANGEROUS in loops and other arithmetical
48// places. Use the signed types unless your variable represents a bit
49// pattern (eg a hash value) or you really need the extra bit. Do NOT
50// use 'unsigned' to express "this value should always be positive";
51// use assertions for this.
52
53typedef unsigned char uint8;
54typedef unsigned short uint16;
55typedef unsigned int uint32;
56#ifdef _MSC_VER
57typedef unsigned __int64 uint64;
58#else
59typedef unsigned long long uint64;
60#endif /* _MSC_VER */
61
62// A type to represent a Unicode code-point value. As of Unicode 4.0,
63// such values require up to 21 bits.
64// (For type-checking on pointers, make this explicitly signed,
65// and it should always be the signed version of whatever int32 is.)
66typedef signed int char32;
67
68// A type to represent a natural machine word (for e.g. efficiently
69// scanning through memory for checksums or index searching). Don't use
70// this for storing normal integers. Ideally this would be just
71// unsigned int, but our 64-bit architectures use the LP64 model
72// (http://en.wikipedia.org/wiki/64-bit_computing#64-bit_data_models), hence
73// their ints are only 32 bits. We want to use the same fundamental
74// type on all archs if possible to preserve *printf() compatability.
75typedef unsigned long uword_t;
76
77// long long macros to be used because gcc and vc++ use different suffixes,
78// and different size specifiers in format strings
79#undef GG_LONGLONG
80#undef GG_ULONGLONG
81#undef GG_LL_FORMAT
82
83#ifdef _MSC_VER /* if Visual C++ */
84
85// VC++ long long suffixes
86#define GG_LONGLONG(x) x##I64
87#define GG_ULONGLONG(x) x##UI64
88
89// Length modifier in printf format string for int64's (e.g. within %d)
90#define GG_LL_FORMAT "I64" // As in printf("%I64d", ...)
91#define GG_LL_FORMAT_W L"I64"
92
93#else /* not Visual C++ */
94
95#define GG_LONGLONG(x) x##LL
96#define GG_ULONGLONG(x) x##ULL
97#define GG_LL_FORMAT "ll" // As in "%lld". Note that "q" is poor form also.
98#define GG_LL_FORMAT_W L"ll"
99
100#endif // _MSC_VER
101
102
103static const uint8 kuint8max = (( uint8) 0xFF);
104static const uint16 kuint16max = ((uint16) 0xFFFF);
105static const uint32 kuint32max = ((uint32) 0xFFFFFFFF);
106static const uint64 kuint64max = ((uint64) GG_LONGLONG(0xFFFFFFFFFFFFFFFF));
107static const int8 kint8min = (( int8) ~0x7F);
108static const int8 kint8max = (( int8) 0x7F);
109static const int16 kint16min = (( int16) ~0x7FFF);
110static const int16 kint16max = (( int16) 0x7FFF);
111static const int32 kint32min = (( int32) ~0x7FFFFFFF);
112static const int32 kint32max = (( int32) 0x7FFFFFFF);
113static const int64 kint64min = (( int64) GG_LONGLONG(~0x7FFFFFFFFFFFFFFF));
114static const int64 kint64max = (( int64) GG_LONGLONG(0x7FFFFFFFFFFFFFFF));
115
116
117typedef uint64 Fprint;
118static const Fprint kIllegalFprint = 0;
119static const Fprint kMaxFprint = GG_ULONGLONG(0xFFFFFFFFFFFFFFFF);
120
121#endif // BASE_INTEGRAL_TYPES_H_