Search code examples
c++cstructfusedesignated-initializer

How to initialize a struct using the c style while using the g++ compiler?


Generally, in order to initialize a struct in c, we could only specify part of the fields. Like below:

static struct fuse_operations hello_oper = {
    .getattr    = hello_getattr,
    .readdir    = hello_readdir,
    .open       = hello_open,
    .read       = hello_read,
};

However, in C++, we should initialize the variables in the struct without naming the fields. Now, what if I would like to initialize a struct using the c style while using the g++ compiler, how to accomplish this? PS: the reason I need to do this is that the struct fuse_operations has too many fields in it.


Solution

  • Unfortunately, even the C++11 version of the C++ standard lacks the designated initializers feature of C99.