I have the following code in a C++ file:
#include <sys/socket.h>
// ...
void someFunc() {
struct msghdr msg = {0}; // <<< Uninitialized member here
}
When I compile with g++
using -Wall -Wextra
, I get warnings:
error: missing initializer for member 'msghdr::msg_namelen'
...same for several other fields
My problem is this: I can't explicitly initialize all the fields, because I don't know what fields will exist (cross-platform) in a struct msghdr
. The struct doesn't have a default constructor, since it's a C struct. I was under the impression that the = {0}
form led to zero-initialization of all fields (which would be fine for me), but the g++
error message suggests not.
What are my options here?