sprintf format %llu not working

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
DoLo_351801
Level 3
Level 3
10 replies posted 10 questions asked 10 sign-ins

Using Psoc4 CY8C4235AXI-483
Environment:
PSoC Creator 4.4 (4.4.0.80)
Culture: English (United States)
OS Version: Microsoft Windows NT 10.0.19043.0
CLR Version: 4.0.30319.42000

I need to print out 64bit Unix Clock values in order to debug.
The %llu format does not work correctly according to my understanding.

I tried I64 but the compiler will not accept it.
I tried to convert to uint32 but I lose too much of the number

Code : (void)snprintf(printBuff, 100u,"RTC value: %llu \r\n", CURRENT_TIME);
UART_PutString(printBuff);

Expected output: RTC value: 1647092905000

Actual output : RTC value: lu

Is the compiler screwed up? Am I screwed up?

 

0 Likes
1 Solution
Len_CONSULTRON
Level 9
Level 9
Beta tester 500 solutions authored 1000 replies posted

DoLo,

I have reproduced the issue you are seeing.

I have a solution.

Go to menu "Project/Build Settings .../ARM GCC xxxx/Linker/General"

Change "Use newlib-nano" to  FALSE.  The select "OK".   Recompile.  

Len_CONSULTRON_0-1647186505148.png

The issue is that the newlib.nano library is a smaller code version of the standard library.  Whoever supplied this library decided that 64-bit operations are very rarely used.  The standard library correctly handles '%llu".

Len
"Engineering is an Art. The Art of Compromise."

View solution in original post

0 Likes
3 Replies
Len_CONSULTRON
Level 9
Level 9
Beta tester 500 solutions authored 1000 replies posted

DoLo,

I have reproduced the issue you are seeing.

I have a solution.

Go to menu "Project/Build Settings .../ARM GCC xxxx/Linker/General"

Change "Use newlib-nano" to  FALSE.  The select "OK".   Recompile.  

Len_CONSULTRON_0-1647186505148.png

The issue is that the newlib.nano library is a smaller code version of the standard library.  Whoever supplied this library decided that 64-bit operations are very rarely used.  The standard library correctly handles '%llu".

Len
"Engineering is an Art. The Art of Compromise."
0 Likes

Thanks Len,

I found this solution earlier but as you suggested; "the newlib.nano library is a smaller code version of the standard library". And as you also stated; "Engineering is an Art. The Art of Compromise." 

I tried it and I already don't have enough room for the larger library. I have a work around and if I want the whole number I can break it up into 2 32 bit words and print them out separately.

As you also stated; "Engineering is an Art. The Art of Compromise." I appreciate the smaller library.

Therefore I will accept this "Compromise". Thank -you

Doug

0 Likes

DoLo,

Breaking up a 64-bit into two 32-bit numbers is easy if your sprintf() output is in HEX.  If it's in decimal, it's a bit more complex as you already found.

For we engineers:  Economic "Compromise" is the most frequent type we need to balance.

Len
"Engineering is an Art. The Art of Compromise."
0 Likes