exc/udemy-cpp/01-basics/01-ranges.cc

23 lines
659 B
C++

#include <cstdint>
#include <cinttypes>
#include <iostream>
/* somewhat overcomplicated, could use macros provided by cstdint */
/* take advantage of two's complement */
#define INT_TEST(BITS) \
std::int##BITS##_t i##BITS = ~(~UINT##BITS##_C(0) << (BITS-1)); \
std::uint##BITS##_t u##BITS = -1; \
std::printf("%-10s %" PRId##BITS "\n", "int"#BITS"_t" , i##BITS); \
std::printf("%-10s %" PRIu##BITS "\n", "uint"#BITS"_t" , u##BITS)
#define BITS X(8) X(16) X(32) X(64)
/* prints sizes of varius (u)intX_t types */
int main()
{
std::cout << "max values of intx_t";
#define X(B) std::cout << '\n'; INT_TEST(B);
BITS
#undef X
}