c++ Initializing a struct with an array as a member

后端 未结 4 1309
旧巷少年郎
旧巷少年郎 2020-12-24 13:28

Edited again because it originally wasn\'t clear that I\'m trying to initialize the arrays at compile time, not at run time...


I\'ve got the following reduced

4条回答
  •  借酒劲吻你
    2020-12-24 13:50

    GCC/Clang support the following extension

    
        typedef struct TestStruct
        {
            int length;
            int* values;
        };
    
        TestStruct t = {3, (int[]){0, 1, 2}};
        TestStruct t2 = {4, (int[]){0, 1, 2, 3}};
    
    

提交回复
热议问题