This creates an array of two iovec
structures on the stack and initializes all members of both array elements to zero.
The initializer {{ 0 }}
only gives an explicit value for the first member of the first array element: iovec[0].iov_base
. The supplied value 0 is converted implicitly to a null pointer.
The other members of the first array element and the other array elements are also initialized, implicitly: pointers to null and arithmetic types to 0.
The line can be written equivalently as
msg_iovec_t iovec[2] = { 0 };
This is the shortest standard way to zero-initialize an entire object, so it is idiomatic. Some compilers might accept an empty initializer list {}
as an extension. Some compilers might issue a warning for this form and require enough braces to designate the first non-aggregate member (two pairs as in the original line).
The effect is similar to
msg_iovec_t iovec[2];
bzero(iovec, sizeof iovec);
except cleaner and portable, because a pointer filled with zero bytes is not necessarily a null pointer.