These are chat archives for esp8266/Arduino

18th
Apr 2018
Redferne Bellini
@Redferne
Apr 18 2018 01:20
Haha. Was really upset about this last week. Thanks, %Lu to printf a uint64_t. Why in gaawks name is PRIu64 defined as %lu?
Bert Melis
@bertmelis
Apr 18 2018 10:15
so it is a bug, or intended? And it's SDK code, not Arduino.
Me No Dev
@me-no-dev
Apr 18 2018 10:19
unsigned int on 32 bit system is uint32_t. unsigned long int is uint64_t
Bert Melis
@bertmelis
Apr 18 2018 11:02
now I'm completely lost
millis() returns uint32_t which is defined as unsigned long. In this logic, uint64_t is unsigned long long.
Bert Melis
@bertmelis
Apr 18 2018 11:30
however, to printf uint64_t I have to use Lu which implicates this is a long double.
Me No Dev
@me-no-dev
Apr 18 2018 11:35
uint32_t is unsigned int
int is int32_t (32 bit system)
millis returns unsigned long for compatibility probably
Bert Melis
@bertmelis
Apr 18 2018 11:59
I take this from c_types.h:
typedef unsigned int        uint32;
typedef unsigned long long  uint64;
Me No Dev
@me-no-dev
Apr 18 2018 12:01
hmmm.. that seems odd
Bert Melis
@bertmelis
Apr 18 2018 12:04
same definitions in stdint.h. So it is very odd printf assumes uint64_t is a long double (which is something comepletely different off course)
maybe I'm looking in the wrong place. I looked into the headers at Arduino/tools/sdk/...
david gauchard
@d-a-v
Apr 18 2018 12:59
This is not odd to me. On 32 bits archs, int/long are 32 and long long is 64. I just tested it again on the esp. It has to be noted that printf(%) deal with int(%d %i) long(%ld %li) or long long (%lld %lli %Ld %Li) (man printf is not clear, speaking of double for L but also saying it's a synonym of ll which applies to integers). It does not known int_t types. This is why these PRI* macro were introduced, and yes at least PRIu64 prints "lu" too here.
david gauchard
@d-a-v
Apr 18 2018 13:17
on 32 and 64 bits archs, we can always cast to (unsigned) int and use %u/id for 32 bits, or cast to (unsigned) long long and use %Lu/id for 64 bits. At least until these PRI* macro are worked-out.