Compilation warning on chprintf.c
Posted: Tue Oct 21, 2014 9:54 pm
Hi,
I just noticed that I currently get an error when compiling chprintf.c:
This is this line:
Which also will give rise to errors in the ftoa() function.
Should it be defined as an 64-bit integer? As long will default to a 32-bit number.
Untested fix (no compilation errors):
Best Regards
Emil
I just noticed that I currently get an error when compiling chprintf.c:
Compiling main.c
../ChibiOS-RT/os/various/chprintf.c:77:24: warning: overflow in implicit constant conversion [-Woverflow]
100000000, 1000000000, 10000000000, 100000000000,
^
../ChibiOS-RT/os/various/chprintf.c:77:24: warning: overflow in implicit constant conversion [-Woverflow]
../ChibiOS-RT/os/various/chprintf.c:78:24: warning: overflow in implicit constant conversion [-Woverflow]
1000000000000, 10000000000000};
This is this line:
Code: Select all
static long pow10[] = {10, 100, 1000, 10000, 100000, 1000000, 10000000,
100000000, 1000000000, 10000000000, 100000000000,
1000000000000, 10000000000000};Should it be defined as an 64-bit integer? As long will default to a 32-bit number.
Untested fix (no compilation errors):
Code: Select all
static int64_t pow10[] = {10, 100, 1000, 10000, 100000, 1000000, 10000000,
100000000, 1000000000, 10000000000, 100000000000,
1000000000000, 10000000000000};
static char *ftoa(char *p, double num, unsigned long precision) {
int64_t l, temp;
if (precision == 0)
precision = FLOAT_PRECISION;
temp = pow10[precision - 1];
l = (int64_t)num;
p = long_to_string_with_divisor(p, l, 10, 0);
*p++ = '.';
l = (int64_t)((num - l) * temp);
return long_to_string_with_divisor(p, l, 10, temp / 10);
}Best Regards
Emil