Anonymous union within struct not in c99?

后端 未结 7 1062
时光说笑
时光说笑 2020-11-28 11:40

here is very simplified code of problem I have:

enum node_type {
    t_int, t_double
};

struct int_node {
    int value;
};

struct double_node {
    double valu         


        
7条回答
  •  忘掉有多难
    2020-11-28 12:23

    Looking at 6.2.7.1 of C99, I'm seeing that the identifier is optional:

    struct-or-union-specifier:
        struct-or-union identifier-opt { struct-declaration-list }
        struct-or-union identifier
    
    struct-or-union:
        struct
        union
    
    struct-declaration-list:
        struct-declaration
        struct-declaration-list struct-declaration
    
    struct-declaration:
        specifier-qualifier-list struct-declarator-list ;
    
    specifier-qualifier-list:
        type-specifier specifier-qualifier-list-opt
        type-qualifier specifier-qualifier-list-opt
    

    I've been up and down searching, and cannot find any reference to anonymous unions being against the spec. The whole -opt suffix indicates that the thing, in this case identifier is optional according to 6.1.

提交回复
热议问题