In one of my project I am using ARM cortex m3. Here I am trying to print a float variable value into a string variable ex. sprintf(sVar, "%f", 22.23); the value returned in sVar is never correct. But if I declare a float global variable, not even use this variable it starts printing value correctly into the sVar variable. Can anyone explain what might be going wrong here? THanks
a local float (if it's unused) will simply get optimised away. so no need to include any support for it. a global is far less likely to get optimised out in this way; unless extreme global optimisation is carried out.
More importantly a local variable will have a random initialized value unless explicitly defined.
If you're printing something out, or calling another external routine with it as a parameter, it's not going to get optimized away