mastupristi wrote on Wednesday, January 25, 2017:
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%c\t%u\t%u\t%u\r\n", 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, "%-*s\t%c\t%u\t%u\t%u\r\n", ( 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