Important changes to forums and questions
All forums and questions are now archived. To start a new conversation or read the latest updates go to forums.mbed.com.
6 years ago.
Strange behavior when using strftime function
I have a program I'm developing that communicates with the PC over USB serially via pc.printf I'm trying to do some things with the real time clock.
Here is a code snippet:
- define btsize 32
strftime(bufftime, btsize, "%m%d%y%I%M%S", localtime(&seconds));
pc.printf("Time = %s", bufftime);
This works just fine when I run it, but here's the strange part: If I include the code above in the program, other parts of the program, totally unrelated to this, locks up the chip when trying to send data to the pc. It always locks up after sending exactly 16 characters. This happens whether or not the above code is ever executed. If I comment out the strftime statement, it all works fine. Also, if I change the buffer size to a larger value, it all works fine. As I said, it doesn't matter if the code is actually executed, all that seems to matter is that it is included in the compile and the buffer size is 32 bytes.
Is this a compiler bug? I can't understand why code that is not even executed would have an effect on some other unrelated code in the program.