/* GCC 4.2.1 problem test case. ~/gcc-4.2.1/bin/gcc -O3 -fno-inline test1.c */ #include #include #include #include static char buffer[65]; char *uint64_t_to_str(int64_t val, int radix) { char *p; long long_val; uint64_t uval; /* Note: overflow in negation -> val undefined. */ if (radix < 0) if (val < 0) val = -val; uval = (uint64_t)val; p = &buffer[sizeof(buffer)-1]; *p= 0; while (uval > (uint64_t) LONG_MAX) { uint64_t quo= uval/(uint32_t) 10; *--p = '0' + (uint32_t) (uval- quo* (uint32_t) 10); uval= quo; } long_val= (long) uval; while (long_val != 0) { long quo= long_val/10; *--p = '0' + (long_val - quo*10); long_val= quo; } cnv: return p; } int main(int argc, char *argv[]) { int64_t x = INT64_MIN; char *str; str = uint64_t_to_str(x, -10); printf("Result: '%s'\n", str); str = uint64_t_to_str(x, 10); printf("Result: '%s'\n", str); return 0; }