Define intX as standard exact-width integer types.

Fixes https://github.com/google/protobuf/issues/823

Change-Id: I7f4c2bfcac2f81d8b34c030dd3d12ea02aaa2264
pull/1843/head
Feng Xiao 8 years ago
parent 868ea59256
commit a17367f44a
  1. 24
      src/google/protobuf/stubs/port.h
  2. 9
      src/google/protobuf/util/time_util.cc

@ -109,15 +109,15 @@ typedef unsigned __int16 uint16;
typedef unsigned __int32 uint32; typedef unsigned __int32 uint32;
typedef unsigned __int64 uint64; typedef unsigned __int64 uint64;
#else #else
typedef signed char int8; typedef int8_t int8;
typedef short int16; typedef int16_t int16;
typedef int int32; typedef int32_t int32;
typedef long long int64; typedef int64_t int64;
typedef unsigned char uint8; typedef uint8_t uint8;
typedef unsigned short uint16; typedef uint16_t uint16;
typedef unsigned int uint32; typedef uint32_t uint32;
typedef unsigned long long uint64; typedef uint64_t uint64;
#endif #endif
// long long macros to be used because gcc and vc++ use different suffixes, // long long macros to be used because gcc and vc++ use different suffixes,
@ -131,8 +131,10 @@ typedef unsigned long long uint64;
#define GOOGLE_ULONGLONG(x) x##UI64 #define GOOGLE_ULONGLONG(x) x##UI64
#define GOOGLE_LL_FORMAT "I64" // As in printf("%I64d", ...) #define GOOGLE_LL_FORMAT "I64" // As in printf("%I64d", ...)
#else #else
#define GOOGLE_LONGLONG(x) x##LL // By long long, we actually mean int64.
#define GOOGLE_ULONGLONG(x) x##ULL #define GOOGLE_LONGLONG(x) INT64_C(x)
#define GOOGLE_ULONGLONG(x) UINT64_C(x)
// Used to format real long long integers.
#define GOOGLE_LL_FORMAT "ll" // As in "%lld". Note that "q" is poor form also. #define GOOGLE_LL_FORMAT "ll" // As in "%lld". Note that "q" is poor form also.
#endif #endif

@ -142,6 +142,13 @@ int64 RoundTowardZero(int64 value, int64 divider) {
} }
} // namespace } // namespace
// Actually define these static const integers. Required by C++ standard (but
// omitting them may still work with some compilers).
const int64 TimeUtil::kTimestampMinSeconds;
const int64 TimeUtil::kTimestampMaxSeconds;
const int64 TimeUtil::kDurationMaxSeconds;
const int64 TimeUtil::kDurationMinSeconds;
string TimeUtil::ToString(const Timestamp& timestamp) { string TimeUtil::ToString(const Timestamp& timestamp) {
return FormatTime(timestamp.seconds(), timestamp.nanos()); return FormatTime(timestamp.seconds(), timestamp.nanos());
} }
@ -174,7 +181,7 @@ string TimeUtil::ToString(const Duration& duration) {
seconds = -seconds; seconds = -seconds;
nanos = -nanos; nanos = -nanos;
} }
result += StringPrintf("%" GOOGLE_LL_FORMAT "d", seconds); result += SimpleItoa(seconds);
if (nanos != 0) { if (nanos != 0) {
result += "." + FormatNanos(nanos); result += "." + FormatNanos(nanos);
} }

Loading…
Cancel
Save