Page 1 of 1

[Issue] Using printf with int64_t types.

Posted: Thu Oct 13, 2016 4:00 am
by kolban
I am working with 3rd party code that has logic similar to the following:

Code: Select all

#include <inttypes.h>
int 64_t bigi = 1234;
printf("Here is a big int %" PRId64 "\n", bigi);
The result should have been:

Code: Select all

Here is a big int 1234
however what is produced is

Code: Select all

Here is a big int ld
Through expansion, the core statement is equivalent to:

Code: Select all

printf("Here is a big int %lld\n", bigi);
I'll be the first to say that the source looks "odd" to me ... however googling around, it is apparently quite legitimate. I'm still searching for a workaround or fix. I don't have the opportunity to easily make a permanent change to the source code so the sample above is what I would like to get working.

Re: Using printf with int64_t types.

Posted: Thu Oct 13, 2016 6:42 am
by ESP_Angus
ESP32 libc (newlib) is compiled with "nano" I/O options, which disables 64-bit formatting. Solution is something like:
printf("Here is a big int %" PRId32 "%" PRId32 "\n", (int)(bigi >> 32), (int)bigi);
Unfortunately I don't know of a way to do this to third-party code without editing it.

Re: Using printf with int64_t types.

Posted: Thu Oct 13, 2016 4:00 pm
by kolban
Oooh ... I had assumed "newlib" was "newlib" but I am starting to get a sense that there is "newlib" and "newlib-nano" which are in some ways distinct from each other. May I ask ... what is the background on "newlib" as distributed by ESP-IDF? I seem to see that it is distributed in binary format. Can you provide us knowledge on the heritage of the source used to compile it? What flags and settings might have been used when the libraries are generated?

For example ... there appears to be (and I could be very wrong here) a flag used when compiling "newlib" that enables printf long-long support ... for example. It seems to be:

enable-newlib-io-long-long

See - http://stackoverflow.com/questions/3294 ... ng-support

By knowing how our version of newlib was compiled, I could see whether that flag was enabled and, if it was ... think about the puzzle one way ... or if I found that it was not enabled, think about the puzzle in a different way.

Re: Using printf with int64_t types.

Posted: Thu Oct 13, 2016 7:55 pm
by ESP_igrr
Here you go:

Source code: https://github.com/espressif/newlib-esp32

Temporary gist with build options used for newlib in ROM: https://gist.github.com/igrr/92f6115dd0 ... 2ba729b519
I will document this in esp-idf, but it will take a few days.

I do find it a bit unfortunate that newlib doesn't use the same weak linking mechanism for 64bit formatting as it does for floating point formatting...

Re: Using printf with int64_t types.

Posted: Thu Oct 13, 2016 8:11 pm
by kolban
THANK YOU that is exceptionally responsive of you. Again, thanks for the fantastic turnaround and I'm going to start studying as soon as possible. My evening will now be full!

2016-11-06: A Github issue now exists ... see https://github.com/espressif/esp-idf/issues/52