Alex Rivera | Logout

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

Asked 2012-08-25T13:07:39.723
8

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.

Edit
Report

1 Answer

0

maybe you can write a variable param function which takes as input the function pointers and assigns the rest of the attribs as NULL. Since you only have one struct - fuse_operations, you can implement the function for only one struct. something like init_struct(int no_op, ...) wherein you pass function pointers to implementations. Its too complex and laborious, but I suppose you can write it once and use it always...

answered 2012-09-25T04:48:06.310

Your Answer