STM32CubeL4 icon indicating copy to clipboard operation
STM32CubeL4 copied to clipboard

Pointer function parameters should be const if the content is not modified

Open MarioMalenica opened this issue 5 years ago • 3 comments

There is an issue with API design, and its really visible with drivers.

If a function parameter is a pointer, and if a function is not modifying the resource that the pointer is pointing to, then that pointer should be declared as "const

Users of your API need to jump through hoops, or insert ugly #pragmas if they need to compile the code with strict settings and with all + extra warnings enabled.

A good example for this is HAL_I2C_Master_Transmit(). Why "uint8_t *pData" is not "const uint8_t *pData"?

With Keil 5 and ARM compiler 6 and in a relatively simple and mid-sized project, if I enable all compiler warnings I'm seeing in average about 120 compilation warnings for latest version (1.16) of this library.

MarioMalenica avatar Oct 27 '20 20:10 MarioMalenica

See also STM32CubeF4#10.

ALABSTM avatar Nov 17 '20 13:11 ALABSTM

Hi @MarioMalenica,

Thank you for your report. We have planned a global update of the HAL and LL drivers since a while. However, this is likely to require some time to be deployed. We cannot share a date for the moment, but we will do our best to have such a global update deployed and released soon. We count on your patience.

Thank you again for having tackled the subject.

With regards,

ALABSTM avatar Nov 17 '20 13:11 ALABSTM

ST Internal Reference: 137863

ALABSTM avatar Dec 12 '23 14:12 ALABSTM