1

The code compiles and runs but I want to handle the warning.

enter image description here

#include <stdio.h>
#include "includes.h"
#include <string.h>

#define DEBUG 1

/* Definition of Task Stacks */
/* Stack grows from HIGH to LOW memory */
#define   TASK_STACKSIZE       2048
OS_STK    task1_stk[TASK_STACKSIZE];
OS_STK    task2_stk[TASK_STACKSIZE];
OS_STK    stat_stk[TASK_STACKSIZE];

/* Definition of Task Priorities */
#define TASK1_PRIORITY      6  // highest priority
#define TASK2_PRIORITY      7
#define TASK_STAT_PRIORITY 12  // lowest priority 

void printStackSize(INT8U prio)
{
    INT8U err;
    OS_STK_DATA stk_data;

    err = OSTaskStkChk(prio, &stk_data);
    if (err == OS_NO_ERR) 
    {
        if (DEBUG == 1)
           printf("Task Priority %d - Used: %d; Free: %d\n", 
                   prio, stk_data.OSFree, stk_data.OSUsed);
    }
    else
    {
        if (DEBUG == 1)
           printf("Stack Check Error!\n");    
    }
}
4

3 回答 3

2

不知道INT32U它的定义很难说,但你可能想要:

printf("Task Priority %d - Used: %u; Free: %u\n", 
        prio, stk_data.OSFree, stk_data.OSUsed);

或者:

printf("Task Priority %d - Used: %lu; Free: %lu\n", 
        prio, stk_data.OSFree, stk_data.OSUsed);
于 2014-04-02T18:41:31.693 回答
1

我相信编译器试图告诉你你的 printf 格式字符串需要一个有符号整数(%d),但你给它的是一个无符号整数。如果是这样,您应该能够通过使用 %u (而不是 %d)或将您的值转换为 (int) 来消除警告(如果值大于有符号的 int 可能会成为问题)按住您的系统...这将导致显示负值)。

于 2014-10-28T22:42:04.977 回答
1

你可以用inttypes.h. 此标头定义固定整数的所有打印和扫描说明符。

所以这

printf("Task Priority %d - Used: %u; Free: %u\n", 
    prio, stk_data.OSFree, stk_data.OSUsed);

变成

printf("Task Priority %d - Used: %" PRIu32 "; Free: %" PRIu32 "\n", 
    prio, stk_data.OSFree, stk_data.OSUsed);
于 2014-10-28T22:08:50.803 回答