c - What's the correct way to sprintf a float? -


i'm trying printf/sprintf floats using code:

sprintf(buff, "fps: %d\n%.4f n %.4f e\nal: %.1fm rl: %.1f\n", fps, p_viewer.p.lat, p_viewer.p.lon, p_viewer.p.alt, p_viewer.roll); 

however i'm getting these warnings when so:

gfx_game_engine.c:300: warning: format '%.4f' expects type 'double', argument 4 has type 'float' gfx_game_engine.c:300: warning: format '%.4f' expects type 'double', argument 5 has type 'float' gfx_game_engine.c:300: warning: format '%.1f' expects type 'double', argument 6 has type 'float' gfx_game_engine.c:300: warning: format '%.1f' expects type 'double', argument 7 has type 'float' 

what's correct way sprintf float? there special format character? feel compiler might casting types somehow , might contribute slowing down.

i'm using dspic33fj128gp802 microcontroller , compiling mplab c30, variant of gcc v3.23.

your variant of gcc broken. in c language, there no way pass float variadic function. default promotions of small types (char, short, , float) @ least int/double apply. i'm guessing whoever hacked gcc microcontroller did disable promotions, idea double slow or hard pass. should flame them hell , back. correct solution, if compiler vendor not want support double correctly, make floating point types same size , equivalent float, not violate promotion rules of language.

another idea: it's possible prototype sprintf missing or wrong, instance int sprintf(); instead of int sprintf(char *, const char *, ...);


Comments

Popular posts from this blog

Add email recipient to all new Trac tickets -

400 Bad Request on Apache/PHP AddHandler wrapper -

php - Change action and image src url's with jQuery -