declaration does not declare anything : warning?

前端 未结 4 2157
暖寄归人
暖寄归人 2021-02-07 09:25
#include 
#include 
#include 

int main()
{
    struct emp
    {
        struct address
        {
              int a;
             


        
4条回答
  •  [愿得一人]
    2021-02-07 09:42

    The reason the warning is displayed is that the first excerpt is not proper C - it has a constraint violation that a standards-compliant C compiler must produce a diagnostisc message for. It violates the C11 6.7.2.1p2:

    Constraints

    1. A struct-declaration that does not declare an anonymous structure or anonymous union shall contain a struct-declarator-list.

    Meaning that it is OK to write

    struct foo {
        struct {
              int a;
        };
    };
    

    since the inner struct declares an anonymous structure, i.e. it is not named.

    But in your example the struct address has a name - address - and therefore it must have a declarator list after the closing brace - declarator list being for example a1 as in your example, or more complex foo, *bar, **baz[23][45].

提交回复
热议问题