hth313 / Calypsi-tool-chains

Overview of the Calypsi tool chain and open source support packages
16 stars 0 forks source link

Printf is not handling some format specifiers correctly #16

Open rebeccabuckingham opened 1 year ago

rebeccabuckingham commented 1 year ago

Noticed with %ld and %lu:

` long x = 1984;

// this prints 'x is %ld', the value of x isn't substitued in the string // removing the 'l' will result in a compiler warning // "format specifies type 'int' but the argument has type 'long'" printf("x is %ld\n", x);

unsigned long y = 9000;

// this prints 'y is %lu', the value of y isn't substituted in the string. // removing the 'l' will result in a compiler warning. printf("y is %lu\n", y);`

hth313 commented 1 year ago

You might need to switch to another printf formatter, see section "16.6 Library on a diet" in the user guide. Another thing that can go wrong with printf is that it uses more stack than some other routines, so you may need to ensure to increase it.

ProxyPlayerHD commented 11 months ago

damn i had no idea that was even an option, i thought float support and such simply didn't exist at all.

though i feel like there should be a warning/message about that from the compiler if you use one of the optional formatting characters like. so for example when you use %f it would tell you that you also need to have --rtattr printf=float in the linker command for that to actually work, and that it will increase code size.

hth313 commented 11 months ago

Yeah, I can add it to the list of things to do. At least when the formatter string is known it could automatically pick the smallest working formatter.