cancel
Showing results for 
Search instead for 
Did you mean: 

LL function causes compiler warning

T B
Associate II
Posted on December 18, 2017 at 16:54

Hi!

The LL library causes a compiler warning (dereferencing type-punned pointer; see below).

Can I ignore this warning?

-Thomas

/STM32Cube_FW_F3_V1.9.0/Drivers/STM32F3xx_HAL_Driver/Inc/stm32f3xx_ll_crc.h:355:3: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]

__STATIC_INLINE void LL_CRC_FeedData16(CRC_TypeDef *CRCx, uint16_t InData)

{

*(uint16_t __IO *)(&CRCx->DR) = (uint16_t) InData;

}
1 ACCEPTED SOLUTION

Accepted Solutions
Posted on December 18, 2017 at 17:14

>>

Can I ignore this warning?

The code explicitly describes to the compile what it wants done. The register has suitable alignment to allow the action. Providing the compiler does what it is told you can ignore the warning.

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

View solution in original post

3 REPLIES 3
Posted on December 18, 2017 at 17:14

>>

Can I ignore this warning?

The code explicitly describes to the compile what it wants done. The register has suitable alignment to allow the action. Providing the compiler does what it is told you can ignore the warning.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Andrew Neil
Evangelist III
Posted on December 19, 2017 at 13:19

warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]

Whenever you get a warning like this from GCC, note that the bit in the square brackets at the end is the option which enables this particular warning - in this case, -Wstrict-aliasing

So you can put this into google[1] to get the description of what this warning is actually detecting:

https://gcc.gnu.org/onlinedocs/gcc/Warning-Options.html

 

You might also choose to disable this particular warning ...

[1] Note: When googling, you will either have to omit the leading hyphen, or put the whole thing in double quotes

(this is because google takes a leading hyphen to mean, 'exclude this term')
Imen.D
ST Employee
Posted on February 28, 2018 at 09:53

Hello,

This issue solved with simplification of current definition UNUSED() macro in stm32xxxx_hal_def.h

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

with

#define UNUSED(X) (void)X  /* To avoid gcc/g++ warnings */

This update will be applied for all STM32Cube families to avoid gcc/g++ warnings.

Best Regards,

Imen

When your question is answered, please close this topic by clicking "Accept as Solution".
Thanks
Imen