Not sure if this is any use to you, but just in case you still need to see if the compiler is configured properly, run this code and compare it with what you've been printing out so far:
Code:
#include <string.h>
#include <limits.h>
/*
Convert an unsigned integer to any base (returns NULL if the buffer is too small)
*/
char* unsigned_integer_to_text(unsigned long long value, char* digits, char* buffer, size_t buffer_limit)
{
/*
Default to decimal
*/
if(digits == NULL)
digits = "0123456789";
/*
Number base is obviously equal to the length of the base's digits
*/
unsigned long long base = strlen(digits);
char* back = buffer;
for(;;)
{
/*
Not enough room...bail out
*/
if(buffer_limit-- == 0)
return NULL;
/*
Calculate and copy the next digit, then divide out
*/
*back++ = digits[value % base];
value /= base;
/*
Done!
*/
if(value == 0)
break;
}
/*
Final check to make sure there's enough room for the sentinal zero
*/
if(buffer_limit == 0)
return NULL;
*back = 0;
/*
Digits are in the wrong order, need to reverse
*/
char* front = buffer;
while(front < back--)
{
char saved = *front;
*front++ = *back;
*back = saved;
}
return buffer;
}
/*
Same as above but uses an internal buffer instead (WARNING: Not thread-safe!)
*/
char* unsigned_integer_to_static_text(unsigned long long value, char* digits)
{
static char global[sizeof(unsigned long long) * CHAR_BIT + 1];
return unsigned_integer_to_text(value, digits, global, sizeof(global));
}
/*
Simple hack to return an "all-bits-set" unsigned value
*/
unsigned long long unsigned_long_long_maximum(void)
{
unsigned long long result = 0;
unsigned char* next = (unsigned char*)&result, * end = next + sizeof(unsigned long long);
while(next != end)
*next++ = 0xff;
return result;
}
/*
A few examples
*/
#include <stdio.h>
int main(void)
{
puts("*** Maximum value of an \"unsigned long long\" on this system ***");
printf("Bits: %zu\n", sizeof(unsigned long long) * CHAR_BIT);
unsigned long long maximum = unsigned_long_long_maximum();
printf("Decimal: %s\n", unsigned_integer_to_static_text(maximum, NULL));
printf("Hex: 0x%s\n", unsigned_integer_to_static_text(maximum, "0123456789ABCDEF"));
printf("Octal: 0%s\n", unsigned_integer_to_static_text(maximum, "01234567"));
printf("Binary: %s\n", unsigned_integer_to_static_text(maximum, "01"));
}