Monday, 15 July 2013

c++ - Compiler macro to test difference between uint64_t and unsigned long long int -



c++ - Compiler macro to test difference between uint64_t and unsigned long long int -

i have c++11 code failing compile because overloaded function redefined same types arguments:

char const* foo(uint64_t) { homecoming "%" priu64; } char const* foo(unsigned long long int) { homecoming "%llu"; }

is there compiler macro can add together check equality between these 2 primitives, , excise sec if equivalent, before compilation?

there other functions homecoming character pointers other types. instance, adding not cause me trouble, though signed , unsigned long long int utilize same number of bytes:

char const* foo(long long int) { homecoming "%lld"; }

so seems insufficient check how much memory type uses. other approaches?

you can inspect maximum values of these type using definitions climits , cstdint:

#include <climits> #include <cstdint> char const* foo(uint64_t) { homecoming "%" priu64; } //ullong_max defined in climits, uint64_max in cstdint #if ullong_max != uint64_max char const* foo(unsigned long long int) { homecoming "%llu"; } #endif

it improve long-term solution create scheme using templates.

c++ c++11 macros uint64 unsigned-long-long-int

No comments:

Post a Comment