Page 2 of 2

Re: Make the type of this parameter a pointer-to-const warning when declaring a FreeRTOS task

Posted: Mon Mar 25, 2024 8:35 pm
by chegewara

To Sonar it does matter, as it tells us "Either add a parameter list or the "&" operator to this use of "HELLO_TASK"." If you have a better idea, please share.
Only when he pass function with wrong signature:
It is still not clear to me how can I avoid this warning.

I have tried to declare my task with const void* param as shown below:

Code: Select all

static void HELLO_TASK(const void *param)
{
    UNUSED(param);
    for (;;)
    {
        printf("This is normal message1 without ANSI color code \n");
        vTaskDelay(1000 / portTICK_PERIOD_MS);
    }
}
This time, I am getting another warning:

Code: Select all

Either add a parameter list or the "&" operator to this use of "HELLO_TASK".
But like i said, i have no idea about SonarLint.

Re: Make the type of this parameter a pointer-to-const warning when declaring a FreeRTOS task

Posted: Mon Mar 25, 2024 10:25 pm
by MicroController
Only when he pass function with wrong signature:
Hmm. I thought that warning was already there even with the 'right' signature. If it only popped up due to the differing function pointer types, then I misunderstood.

Anyway, revising my first answer, it's better to have/disable Sonar complaining about the 'pointer-to-const' than to force a potentially incompatible function pointer type through the compiler.

Re: Make the type of this parameter a pointer-to-const warning when declaring a FreeRTOS task

Posted: Tue Mar 26, 2024 5:32 am
by zazas321
Thanks for all the suggestions.

I will also make a post to sonar community regarding this, perhaps they can shed some light as this seems to be false warning in this particular case.

As have been suggested, a correct way to declare a task is as following:

Code: Select all


static void HELLO_TASK(void *param);

static void HELLO_TASK(void *param)
{
    UNUSED(param);
    for (;;)
    {
        printf("This is normal message1 without ANSI color code \n");
        vTaskDelay(1000 / portTICK_PERIOD_MS);
    }
}
and it should not return any warnings in this particular case. Is that correct?



Additionally, I can make the error go away if I use const void * param and also pass the address of a function to xTaskCreate. as shown below:

Code: Select all


#include <stdio.h>
#include <inttypes.h>
#include "sdkconfig.h"
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "esp_chip_info.h"
#include "esp_flash.h"
#include "task_monitor.h"
#include "UART0.h"

#define UNUSED(x) (void)(x)

static void HELLO_TASK(const void *param);

void app_main(void)
{
    printf("Hello world!\n");
    xTaskCreate(&HELLO_TASK, "HELLO_TASK", 4096, NULL, 3, NULL);

}

static void HELLO_TASK(const void *param)
{
    UNUSED(param);
    for (;;)
    {
        printf("This is normal message1 without ANSI color code \n");
        vTaskDelay(1000 / portTICK_PERIOD_MS);
    }
}


The above will not show any errors/warnings according to SonarLint but this does not seem like an optimal solution.