为什么指定的初始化器没有用g ++实现

是否有任何具体原因为什么没有将指定的初始值设定项添加到g ++?是因为C99标准迟到了,g ++是早期开发的,之后人们不关心这个问题,或者在C ++语法中实现指定的初始化器存在一些固有的困难?     
已邀请:
正如我在评论中指出的那样,G ++不支持C99标准指定的初始化程序,但它确实支持允许指定初始化程序的C90的GNU扩展。所以这不起作用:
union value_t {
    char * v_cp;
    float v_f;
};
union value_t my_val = { .v_f = 3.5f };
但这样做:
union value_t my_val = { v_f: 3.5f };
这似乎是C和C ++标准委员会之间协调的不良互动(没有特别好的理由说明为什么C ++不支持C99语法,他们只是没有考虑过它)和GCC政治(C ++不应该' t支持C99语法只是因为它在C99中,但是它应该支持GNU扩展语法,它实现了完全相同的东西,因为这是一个可以应用于任何一种语言的GNU扩展。     
我今天遇到了同样的问题。 g ++与-std = c ++ 11和c ++ 14确实支持指定的初始值设定项,但你仍然可以得到一个编译错误“test.cxx:78:9:抱歉,未实现:不支持非平凡的指定初始值设定项”如果你不要按照定义成员的顺序初始化结构。举个例子
struct x
{
    int a;
    int b;
};

// This is correct
struct x x_1 = {.a = 1, .b = 2};
// This will fail to compile with error non-trivial designated initializer
struct x x_2 = {.b = 1, .a = 2};
    
C ++不支持这一点。它似乎甚至不会出现在C ++ 0x标准中:http://groups.google.com/group/comp.std.c++/browse_thread/thread/8b7331b0879045ad?pli = 1 另外,为什么要尝试用G ++编译Linux内核?     
至少从g ++ - 4.8开始,默认情况下现在支持此功能。     
匿名工会怎么样? 在C我可以这样:
struct vardir_entry {
    const uint16_t id;
    const uint8_t sub;
    const char *name;
    const uint8_t type;

    const union {   
        struct vardir_lookup lookup;
        struct vardir_min_max_conf minmax;       
    };

    const union {
        const struct vardir_value_target_const const_value;
        const struct vardir_value_target value;
    };
};
并初始化如下:
static const struct vardir_entry _directory[]{
        { .id = 0xefef, .sub = 0, .name = "test", .type = VAR_UINT32, .minmax = { .min = 0, .max = 1000 }, .value = VARDIR_ENTRY_VALUE(struct obj, &obj, member) }
    };
但是在g ++下,即使使用c ++ 14,这也会产生相同的“抱歉,未实现”错误。当我们至少想要用C ++测试框架对C代码进行单元测试时,我们需要能够在C ++中定义C变量。事实上,C的这种有价值的功能得不到支持是非常遗憾的。     
根据 http://gcc.gnu.org/c99status.html 指定的初始化程序已经实施。 你用的是什么版本的g ++? (试试g ++ - 版本)     

要回复问题请先登录注册