For many years, I initialized mine struct stat
as follows:
#include <sys/stat.h>
struct stat foo = {0};
In particular, that {0}
sets all fields to zero, which is equivalent memset (&foo, NULL, sizeof foo);
. Now with C ++ 11, this has led to warnings:
foo.cpp:2:19: warning: missing field 'st_mode' initializer [-Wmissing-field-initializers]
struct stat s = {0};
^
This is due to the new C ++ 11 initializer syntax, and the warning implies that I am not initializing all members. What is the preferred way to create and initialize struct stat
in C ++ 11?
source
share