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

chegewara
Posts: 2375
Joined: Wed Jun 14, 2017 9:00 pm

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

Postby chegewara » Mon Mar 25, 2024 8:35 pm

MicroController wrote:
Mon Mar 25, 2024 8:29 pm

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:
zazas321 wrote: 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.

MicroController
Posts: 1725
Joined: Mon Oct 17, 2022 7:38 pm
Location: Europe, Germany

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

Postby MicroController » Mon Mar 25, 2024 10:25 pm

chegewara wrote:
Mon Mar 25, 2024 8:35 pm
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.

zazas321
Posts: 231
Joined: Mon Feb 01, 2021 9:41 am

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

Postby zazas321 » Tue Mar 26, 2024 5:32 am

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.

Who is online

Users browsing this forum: No registered users and 376 guests