On 26/09/2023 11:44, Zachary Leaf wrote:
In that case we need to explicitly memset() rather than initialise the struct with {0}, since the latter doesn't set the padding.
Well that's fascinating, I hadn't realised that! Found a nice blog post [1] regarding that can of worms. TL;DR is that padding does get zero-init at -O2 with both Clang and GCC, but that is not required by the standard (at least not yet). So yes, an explicit memset() is a good idea.
Kevin
[1] https://interrupt.memfault.com/blog/c-struct-padding-initialization