Demonstration of the use of sprintf() causing a run time problem with RTOS.

Dependencies:   mbed

Files at this revision

API Documentation at this revision

Comitter:
tylerjw
Date:
Thu Feb 16 14:03:52 2012 +0000
Commit message:

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Thu Feb 16 14:03:52 2012 +0000
@@ -0,0 +1,29 @@
+#include "mbed.h"
+#include "rtos.h"
+
+DigitalOut led1(LED1);
+DigitalOut led2(LED2);
+
+char* teststring = "";
+int testint = 65;
+
+// uncomment only one of the sprintf functions at a time to see it fail at that point
+
+void led2_thread(void const *argument) {
+    while (true) {
+        led2 = !led2;
+        //sprintf(teststring, "This is a test: %d", testint);
+        Thread::wait(1000);
+    }
+}
+
+int main() {
+    Thread thread(led2_thread);
+    //sprintf(teststring, "This is a test: %d", testint);
+    
+    while (true) {
+        led1 = !led1;
+        sprintf(teststring, "This is a test: %d", testint);
+        Thread::wait(500);
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Thu Feb 16 14:03:52 2012 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/14f4805c468c