non-trivial designated initializers not supported

前端 未结 6 1621
隐瞒了意图╮
隐瞒了意图╮ 2020-12-24 04:23

I have a structure as follows:

struct app_data
{
    int port;
    int ib_port;
    unsigned size;
    int tx_depth;
    int sockfd;
    char *servername;
           


        
6条回答
  •  轮回少年
    2020-12-24 05:07

    the order of initialization needs to be in the exact order of declaration.

    typedef struct FOO
    {
        int a;
        int b;
        int c;
    }FOO;
    
    FOO foo   = {.a = 1, .b = 2}; // OK
    FOO foo1  = {.a = 1};         // OK
    FOO foo2  = {.b = 2, .a = 1}; // Error sorry, unimplemented: non-trivial designated initializers not supported
    FOO foo3  = {.a = 1, .c = 2}; // Error sorry, unimplemented: non-trivial designated initializers not supported
    

    I understand that this means that the compiler has no support for name-oriented, out-of-order, member initialization.

    Need to initialize the struct in the old fashioned way. I keep the variable names for clarity, but I have to initialize them in order, and not skip a variable.

    I can stop the initialization at any variable, but can't initialize variables that come of that.

提交回复
热议问题