Question

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");    
    }
}
Was it helpful?

Solution

Without knowing the definition of INT32U it's hard to say, but you probably want:

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

or:

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

OTHER TIPS

You could try it with inttypes.h. This header defines all print and scan specifier for fixed integers.

So this

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

Becomes

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

I believe the compiler is trying to tell you that your printf format string is expecting a signed integer (%d) but you are giving it an unsigned integer. If so you should be able to get rid of the warnings by either using a %u (instead of %d) or by casting your values to (int) (which could possibly be an issue if the values got larger than a signed int can hold on your system ... this would cause negative values to be displayed).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top