Aggregate objects, such as structures or arrays, are initialized with initializers = { ... } . You can either provide initializers for consecutive members of the structure starting with the first, or use the approach labeled C99
static struct timespec ts = { .tv_sec = 0 };
Please note that the approach = { ... } more universal than it might seem at first glance. Scalar objects can also be initialized with such initializers.
static int foo = { 0 };
Also note that = { 0 } will reset all data fields in the aggregated object, not just the first one.
Lastly, keep in mind that objects with a static storage duration are always null automatically initialized, which means that if you simply declare
static struct timespec ts;
you are guaranteed to get a zero initialized object. There is no need to do this explicitly.
source share