question about vTaskList()

inthe function vTaskList() I found: ~~~ /* Write the task name to the string, padding with spaces so it can be printed in tabular form more easily. */ pcWriteBuffer = prvWriteNameToBuffer( pcWriteBuffer, pxTaskStatusArray[ x ].pcTaskName ); /* Write the rest of the string. */ sprintf( pcWriteBuffer, “t%ct%ut%ut%urn”, cStatus, ( unsigned int ) pxTaskStatusArray[ x ].uxCurrentPriority, ( unsigned int ) pxTaskStatusArray[ x ].usStackHighWaterMark, ( unsigned int ) pxTaskStatusArray[ x ].xTaskNumber ); pcWriteBuffer += strlen( pcWriteBuffer ); ~~~ I wonder why the task name is written using prvWriteNameToBuffer() and not using the subsequent sprintf with the right formatting. And why is called strlen instead of using the output of sprintf If I write: ~~~ pcWriteBuffer += sprintf( pcWriteBuffer, “%-*st%ct%ut%ut%urn”, ( configMAX_TASK_NAME_LEN – 1 ), pxTaskStatusArray[ x ].pcTaskName, cStatus, ( unsigned int ) pxTaskStatusArray[ x ].uxCurrentPriority, ( unsigned int ) pxTaskStatusArray[ x ].usStackHighWaterMark, ( unsigned int ) pxTaskStatusArray[ x ].xTaskNumber ); ~~~ It works (I use gcc toolchain). why do not use this? best regards Max

question about vTaskList()

…because doing that in GCC can, depending on your tools, more than double the size of your executable image, massively increase the task’s stack requirements, and unknowingly result in a call to malloc() 🙂 FreeRTOS is often used with very (extremely) stripped down versions of sprintf() (we provide some ourselves) that only provide functionality that is actually required, use minimal stack, are thread safe, etc.. If we relied on a full sprintf() implementation then the code would not be portable to those applications.