alekmaul / pvsneslib

PVSnesLib : A small, open and free development kit for the Nintendo SNES

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

sprintf issue with 32 bits variables

alekmaul opened this issue · comments

When you want to use u32 and put content in a string, the result is not OK
here is an example:
sprintf((char *)tmphud, "%05Lu", (u32) hiscore);
example, if hiscore is 0000c350 for 50000, result is garbage

tmphud is defined with u8 tmphud[16];

Does itoa work?

So, it turns out the results are not entirely garbage, instead, it is only reading 16-bits at a time. So if you pass in a 32-bit value, you can print it as two consecutive 16-bit values. This, of course, isn't ideal.

Well, I need to investigate again this issues. I thought it was fixed with last version of tcc.

I tested on Hello world example
image
with:

u32 hiscore;
u8 tmphud[16]; 

    hiscore=0xdeadcafe;
    sprintf((char *)tmphud, "%05Lu", (u32) hiscore);
    consoleDrawText(10, 20, tmphud);

And it works, I close this defect.