declaration does not declare anything : warning?

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

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


        
4条回答
  •  滥情空心
    2021-02-07 09:56

    The syntax of a structure definition is:

    struct identifier {
        type member_name;
    
        // ...
    
    };
    

    If you add an identifier just after the closing curly brace, you're declaring a variable with that defined struct.

    In your first example the compiler consider the address struct as member type. it's like if you writes:

    struct identifier {
    
        type ; // No member name is specified
        type a1;
    
        // ...
    
    }
    

    But in the second example you specified the member name:

    struct identifier {
    
        type a1; // Member name specified
    
        // ...
    
    }
    

    And here is an example of the warning: http://ideone.com/KrnYiE.

提交回复
热议问题