Avoid redefining PRI macros on Linux (#4055)
* Avoid redefining `PRI` macros on Linux The fixed width 64-bit integer types are defined differently per platform. Some platforms define it as "long", others define it as "long long". For consistency, `AZ::u64` or `AZ::s64` is always defined to "long long". However, this causes problems for formatting those types, because on platforms where `uint64_t` is a `long`, `PRIu64` gives the wrong format string for `AZ::u64`. Previously this was fixed by redefining the `PRI` macros so that they work for `AZ::u64`, but that breaks the ability to format `uint64_t`. We could add an AZ-specific version of the `PRI` macros for 64-bit integer types, but we don't really need to, since they are `long long` on every platform we support. * Use `%ll` for `AZ::u64` * Use `PRIu64` for `uint64_t` Signed-off-by: Chris Burel <burelc@amazon.com> * Avoid redefining `PRI` macros in CryCommon Signed-off-by: Chris Burel <burelc@amazon.com>
This commit is contained in:
@@ -51,20 +51,9 @@
|
||||
#undef AZ_RESTRICTED_SECTION_IMPLEMENTED
|
||||
#elif defined(LINUX) || defined(APPLE)
|
||||
#define __STDC_FORMAT_MACROS
|
||||
#include <inttypes.h>
|
||||
#if defined(APPLE) || defined(LINUX64)
|
||||
// int64 is not the same type as the operating system's int64_t
|
||||
#undef PRIX64
|
||||
#undef PRIx64
|
||||
#undef PRId64
|
||||
#undef PRIu64
|
||||
#define PRIX64 "llX"
|
||||
#define PRIx64 "llx"
|
||||
#define PRId64 "lld"
|
||||
#define PRIu64 "llu"
|
||||
#endif
|
||||
#include <cinttypes>
|
||||
#else
|
||||
#include <inttypes.h>
|
||||
#include <cinttypes>
|
||||
#endif
|
||||
|
||||
#if !defined(PRISIZE_T)
|
||||
|
||||
@@ -125,7 +125,7 @@ bool CBinaryXmlNode::getAttr(const char* key, int64& value) const
|
||||
const char* svalue = GetValue(key);
|
||||
if (svalue)
|
||||
{
|
||||
azsscanf(svalue, "%" PRId64, &value);
|
||||
value = strtoll(svalue, nullptr, 10);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
@@ -137,14 +137,7 @@ bool CBinaryXmlNode::getAttr(const char* key, uint64& value, bool useHexFormat)
|
||||
const char* svalue = GetValue(key);
|
||||
if (svalue)
|
||||
{
|
||||
if (useHexFormat)
|
||||
{
|
||||
azsscanf(svalue, "%" PRIX64, &value);
|
||||
}
|
||||
else
|
||||
{
|
||||
azsscanf(svalue, "%" PRIu64, &value);
|
||||
}
|
||||
value = strtoull(svalue, nullptr, useHexFormat ? 16 : 10);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
||||
@@ -400,7 +400,7 @@ bool CXmlNode::getAttr(const char* key, int64& value) const
|
||||
const char* svalue = GetValue(key);
|
||||
if (svalue)
|
||||
{
|
||||
azsscanf(svalue, "%" PRId64, &value);
|
||||
value = strtoll(key, nullptr, 10);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
@@ -412,14 +412,7 @@ bool CXmlNode::getAttr(const char* key, uint64& value, bool useHexFormat) const
|
||||
const char* svalue = GetValue(key);
|
||||
if (svalue)
|
||||
{
|
||||
if (useHexFormat)
|
||||
{
|
||||
azsscanf(svalue, "%" PRIX64, &value);
|
||||
}
|
||||
else
|
||||
{
|
||||
azsscanf(svalue, "%" PRIu64, &value);
|
||||
}
|
||||
value = strtoull(key, nullptr, useHexFormat ? 16 : 10);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
||||
Reference in New Issue
Block a user