cancel
Showing results for 
Search instead for 
Did you mean: 

Is the "register" storage class specifier necessary in STM32 LL interfaces?

Rob.Riggs
Senior

I am doing C++17 development on the STM32L4. The register storage class specifier has been deprecated for quite some time in C++ and is now forbidden. It seems to be used extensively in the STM32L4xx ADC LL interface. This causes quite a large number of warnings in any C++ code that includes the HAL header. This would not be a problem if the register usage was confined to C code. But it exists in macros defined in stm32l4xx_ll_adc.h which gets pulled in by any code that uses the HAL.

Is the use of the register keyword useful in these places? If it is not useful, it should be removed. If it is useful then I would prefer to see it confined to C source where it will be used. If it must remain in the header, please consider replacing it with a REGISTER macro that is only defined when __cplusplus is not defined.

These are the sort of warnings I am seeing with GCC:

Drivers/STM32L4xx_HAL_Driver/Inc/stm32l4xx_ll_adc.h:5210:21: warning: ISO C++1z does not allow 'register' storage class specifier [-Wregister]
   register uint32_t AnalogWDMonitChannels = (READ_BIT(*preg, AWDy) & AWDy & ADC_AWD_CR_ALL_CHANNEL_MASK);

For now I am compiling with -Wno-register to avoid these warnings. But that seems less than ideal.

1 REPLY 1

The register directive has been useless for more years than I care to remember. That and all the people who think "register level" coding is "more efficient" whilst failing to understand that the optimizer can't fold volatile variable interaction.

Upvoting for more rigour, and getting posts off my feed. @ST Community​ 

See also

https://community.st.com/s/question/0D50X00009bN5OkSAK/when-will-cubemx-code-generation-and-stm32-libraries-be-updated-for-c-as-they-do-not-work-properly

Tips, buy me a coffee, or three.. PayPal Venmo Up vote any posts that you find helpful, it shows what's working..