During a debugging session, I found out that snprintf does not work as expected when compiling code using avr-gcc. The sample code should simply convert the floating point value 3999.9f to its character representation.
Here is a minimal test case:
int TestSnprintf(void) { const float inputValue = 3999.9f; char buf[7U] = {0, 0, 0, 0, 0, 0, 0}; const uint8_t bufferSize = 7U; if(6 != snprintf(buf, bufferSize, "%06.1f", inputValue)) { return -1; } if( buf[0] != '3' || buf[1] != '9' || buf[2] != '9' || buf[3] != '9' || buf[4] != '.' || buf[5] != '9' || buf[6] != '\0') { return -2; } return 0; } int main(void) { int retVal = TestSnprintf(); return 0; }
Combining this sample code with avr-gcc and running it with Atmel Studio 7 gives a return value of -2 . This means that snprintf is not working.
What if you have already tried?
Here is a screenshot from a debugging session that shows that the return value is -2 .

This shows that during debugging buf is in scope: 
Question
What am I doing wrong?
Decision
First of all, thank you all for your help! As pointed out by @manilo, the following linker options were missing:
-Wl,-u,vfprintf -lprintf_flt -lm
source share