chprintf for 64 bit values
Posted: Thu Aug 25, 2016 4:36 pm
I have a GPS unit with that leaves me with ten digits to print out, so I've needed to use int64_t to store these coordinates.
My maths in the code are working with these values well, since debugging shows the variables turning out how they should be, but I'm having trouble printing the values to the serial terminal.
I always hate the ambiguity of "integer" and "long" as the chprintf description uses:
* The following parameter types (p) are supported:
* - <b>x</b> hexadecimal integer.
* - <b>X</b> hexadecimal long.
* - <b>o</b> octal integer.
* - <b>O</b> octal long.
* - <b>d</b> decimal signed integer.
* - <b>D</b> decimal signed long.
* - <b>u</b> decimal unsigned integer.
* - <b>U</b> decimal unsigned long.
* - <b>c</b> character.
* - <b>s</b> string.
Since chprintf() seems to be unable to printf 64 bit numbers, does that mean longs are 32 bit? This is not what I expected.
I assumed a long was 64 bits, so I've been calling
Notice how both variables are the same value, but the terminal output is:
Interesting, yes? I'm having trouble interpreting this output since neither of the variables are getting optimized out as far as I can tell. They are volatile. Is there a way I can print 64 bit ints?
My maths in the code are working with these values well, since debugging shows the variables turning out how they should be, but I'm having trouble printing the values to the serial terminal.
I always hate the ambiguity of "integer" and "long" as the chprintf description uses:
* The following parameter types (p) are supported:
* - <b>x</b> hexadecimal integer.
* - <b>X</b> hexadecimal long.
* - <b>o</b> octal integer.
* - <b>O</b> octal long.
* - <b>d</b> decimal signed integer.
* - <b>D</b> decimal signed long.
* - <b>u</b> decimal unsigned integer.
* - <b>U</b> decimal unsigned long.
* - <b>c</b> character.
* - <b>s</b> string.
Since chprintf() seems to be unable to printf 64 bit numbers, does that mean longs are 32 bit? This is not what I expected.
I assumed a long was 64 bits, so I've been calling
Code: Select all
volatile int64_t test1 = 4000000000;
volatile int64_t test2 = 4000000000;
chprintf((BaseSequentialStream *)&SD2, "%D,%D\r\n",test1, test2);
Notice how both variables are the same value, but the terminal output is:
Code: Select all
-294967296,0
Interesting, yes? I'm having trouble interpreting this output since neither of the variables are getting optimized out as far as I can tell. They are volatile. Is there a way I can print 64 bit ints?