+TCP falis build with gcc 9

I get an error compiling FreeRTOS+TCP with gcc9

amazon-freertos/lib/FreeRTOS-Plus-TCP/FreeRTOS_IP.c:1850:17: error: taking address of packed member of 'struct xUDP_HEADER' may result in an unaligned pointer value [-Werror=address-of-packed-member]
 1850 |   pusChecksum = ( uint16_t * ) ( &( pxProtPack->xUDPPacket.xUDPHeader.usChecksum ) );
      |                 ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

this is very annoying. At the moment I am going to fix it using void pointers and the functions memcpy() and memset().

I ask you to analyze it and find the right way to do it.

best regards
Max

Why not using -Wno-address-of-packed-member instead of forcing a -Werror if your MCU can handle unaligned memory access w/o serious penalty ?

The company I work for imposes the rule of using -Wall and -Werror. The MCUs I have the problem with are ARM Cortex-M4 and Cortex-M7.
I don’t think they can handle unaligned access.

best regards
Max

Hello, I would go for the same option as proposed by @hs2.
FreeRTOS+TCP indeed uses packed structures in order to increase ease of coding and also performance.
E.g. you do not want to use a memcpy() to copy 4 bytes. A 32-bit assignment is much more efficient. All accesses of this type have been checked for their correctness.

Sorry, I’m just seeing this post. FreeRTOS+TCP has been thoroughly tested on both ARM Cortex-M4/M7. The access of data is never badly aligned: either 8, 16 or 32 bits.

I think you’re right. That’s why I finally used pragma to disable the warning -Waddress-of-packed-member only where it’s needed, for example:

#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Waddress-of-packed-member"
pusChecksum = ( uint16_t * ) ( &( pxProtPack->xUDPPacket.xUDPHeader.usChecksum ) );
#pragma GCC diagnostic pop