#include <stdio.h>
#include <stdint.h>
#include <string.h>
typedef union {
// UINT64_MAX is 20 bytes.
// 23 bytes of zeros for copying.
char view_8[20 + 23];
uint64_t view_64[3];
} Print_Buffer;
void print_internal_uint64_t(uint64_t v) {
Print_Buffer output = {0};
size_t i = 0;
while(true) {
i += 1;
output.view_8[20 - i] = (v % 10) + '0';
v /= 10;
if(v == 0) {
break;
}
}
#if 0
// Unaligned loads
output.view_64[0] = *(uint64_t *)&output.view_8[20 - i];
output.view_64[1] = *(uint64_t *)&output.view_8[20 - i + 8];
output.view_64[2] = *(uint64_t *)&output.view_8[20 - i + 16];
#else
// Standard compliant
memmove(&output.view_8[0], &output.view_8[20 - i], 24);
#endif
printf("%s\n", output.view_8);
}
void print_n(uint64_t v) {
printf("uint64_t: ");
print_internal_uint64_t(v);
}
void print_n(int64_t v) {
printf("int64_t: ");
if(v < 0) {
printf("-");
v = -v;
}
print_internal_uint64_t(v);
}
int main() {
print_n(UINT64_MAX);
print_n(18446744073709551);
print_n(0UL);
print_n(1UL);
print_n(9UL);
print_n(50UL);
print_n(62UL);
print_n(73L);
print_n(-84L);
print_n(99999999L);
print_n(45645656L);
print_n(35123123123L);
print_n(4564565645645656L);
return 0;
}