Statistics
| Branch: | Revision:

root / include / platdep / intxtypes.h @ 7f251033

History | View | Annotate | Download (4.77 KB)

1
//==========================================================================
2
//  INTXTYPES.H - part of
3
//                     OMNeT++/OMNEST
4
//            Discrete System Simulation in C++
5
//
6
//==========================================================================
7

    
8
/*--------------------------------------------------------------*
9
  Copyright (C) 1992-2008 Andras Varga
10
  Copyright (C) 2006-2008 OpenSim Ltd.
11

12
  This file is distributed WITHOUT ANY WARRANTY. See the file
13
  `license' for details on this and other legal matters.
14
*--------------------------------------------------------------*/
15

    
16
#ifndef __INTXTYPES_H
17
#define __INTXTYPES_H
18

    
19
#include <limits.h>   // __WORDSIZE
20

    
21
// All systems except Visual C++ are expected to have <stdint.h>
22
#if defined SWIG || defined _MSC_VER
23
#define HAVE_STDINT_H 0
24
#else
25
#define HAVE_STDINT_H 1
26
#endif
27

    
28
//
29
// Make intX_t and uintX_t types available
30
//
31
#if HAVE_STDINT_H
32
  // include C99 header
33
  #include <stdint.h>
34
#elif defined _MSC_VER
35
  typedef __int8              int8_t;
36
  typedef __int16             int16_t;
37
  typedef __int32             int32_t;
38
  typedef __int64             int64_t;
39
  typedef unsigned __int8     uint8_t;
40
  typedef unsigned __int16    uint16_t;
41
  typedef unsigned __int32    uint32_t;
42
  typedef unsigned __int64    uint64_t;
43
#else
44
  // the following should work on most systems (and in envir we check
45
  // the correctness of these definitions)
46
  typedef signed char         int8_t;
47
  typedef short               int16_t;
48
  typedef int                 int32_t;
49
  typedef long long           int64_t;
50
  typedef unsigned char       uint8_t;
51
  typedef unsigned short      uint16_t;
52
  typedef unsigned int        uint32_t;
53
  typedef unsigned long long  uint64_t;
54
#endif
55

    
56
//
57
// MIN/MAX macros for integral types, copied from <stdint.h>.
58
// Note that we need to define them ourselves, because if
59
// <stdint.h> gets included before us, it's too late
60
// to turn on __STDC_LIMIT_MACROS.
61
//
62

    
63
// Minimum of signed integral types.
64
#ifndef INT8_MIN
65
#define INT8_MIN      (-128)
66
#endif
67

    
68
#ifndef INT16_MIN
69
#define INT16_MIN     (-32767-1)
70
#endif
71

    
72
#ifndef INT32_MIN
73
#define INT32_MIN     (-2147483647-1)
74
#endif
75

    
76
#ifndef INT64_MIN
77
#define INT64_MIN     (-9223372036854775807LL-1)
78
#endif
79

    
80
// Maximum of signed integral types.
81
#ifndef INT8_MAX
82
#define INT8_MAX      (127)
83
#endif
84

    
85
#ifndef INT16_MAX
86
#define INT16_MAX     (32767)
87
#endif
88

    
89
#ifndef INT32_MAX
90
#define INT32_MAX     (2147483647)
91
#endif
92

    
93
#ifndef INT64_MAX
94
#define INT64_MAX     (9223372036854775807LL)
95
#endif
96

    
97
// Maximum of unsigned integral types.
98
#ifndef UINT8_MAX
99
#define UINT8_MAX     (255)
100
#endif
101

    
102
#ifndef UINT16_MAX
103
#define UINT16_MAX    (65535)
104
#endif
105

    
106
#ifndef UINT32_MAX
107
#define UINT32_MAX    (4294967295U)
108
#endif
109

    
110
#ifndef UINT64_MAX
111
#define UINT64_MAX    (18446744073709551615ULL)
112
#endif
113

    
114

    
115
//
116
// We prefer shorter names for ints. If they collide with other headers,
117
// #undef them after #including omnetpp.h.
118
//
119
#ifndef int8
120
#define int8     int8_t
121
#endif
122

    
123
#ifndef int16
124
#define int16    int16_t
125
#endif
126

    
127
#ifndef int32
128
#define int32    int32_t
129
#endif
130

    
131
#ifndef int64
132
#define int64    int64_t
133
#endif
134

    
135
#ifndef uint8
136
#define uint8    uint8_t
137
#endif
138

    
139
#ifndef uint16
140
#define uint16   uint16_t
141
#endif
142

    
143
#ifndef uint32
144
#define uint32   uint32_t
145
#endif
146

    
147
#ifndef uint64
148
#define uint64   uint64_t
149
#endif
150

    
151

    
152
//
153
// printf type specifier for int64.
154
//
155
// Note: %I64d is only used with VC++ 7.1 and MinGW gcc 3.4.x; once we
156
// drop support for these compilers, this macro can be dropped altogether
157
//
158
// Note2: on 64-bit platforms, gcc defines int64_t to be long, so
159
// we need to use %ld (%lld generates warnings). We recognize 64-bit
160
// platforms by __WORDSIZE (from <bits/wordsize.h>, #included by <limits.h>)
161
//
162
#if defined(_MSC_VER) || defined(__MINGW32__)
163
#   define INT64_PRINTF_FORMAT   "I64"
164
#elif __WORDSIZE == 64
165
#   define INT64_PRINTF_FORMAT   "l"
166
#else
167
#   define INT64_PRINTF_FORMAT   "ll"
168
#endif
169

    
170
//
171
// cCommBuffer and cHasher need to process long long and unsigned long long
172
// (which should be a different type from long, and at least 64 bits in size).
173
// However, earlier versions of MSVC (7.1 and before) don't understand
174
// long long but have __int64 instead. MSVC 8.0 and above are OK.
175
// The following typedefs can be removed when we drop support for MVSC 7.1.
176
//
177
// These types are NOT part of the OMNeT++ public API. Do not use them
178
// except in cCommBuffer implementations.
179
//
180
#ifdef _MSC_VER
181
typedef __int64            opp_long_long;
182
typedef unsigned __int64   opp_unsigned_long_long;
183
#else
184
typedef long long          opp_long_long;
185
typedef unsigned long long opp_unsigned_long_long;
186
#endif
187

    
188
#if defined(_MSC_VER) || defined(__MINGW32__)
189
#define LONGLONG_PRINTF_FORMAT  "I64"
190
#else
191
#define LONGLONG_PRINTF_FORMAT  "ll"
192
#endif
193

    
194

    
195
//
196
// string-to-int64 conversion
197
//
198
#ifdef _MSC_VER
199
#define strtoll   _strtoi64
200
#define strtoull  _strtoui64
201
#endif
202

    
203
#endif
204