Compatible types and structures in C

后端 未结 5 1075
深忆病人
深忆病人 2020-12-14 02:18

I have the following code:

int main(void)
{
    struct { int x; } a, b;
    struct { int x; } c;
    struct { int x; } *p;

    b = a;   /* OK */
    c = a;          


        
5条回答
  •  长情又很酷
    2020-12-14 03:08

    Interestingly Clang gives the following:

    error: incompatible type assigning 'struct ', expected 'struct '
    
    warning: incompatible pointer types assigning 'struct  *', expected 'struct  *'
    

    It seems that if two (or more) anonymous structs are declared then the compiler does some internal magic which specifies which specific anonymous struct is being referred too.

提交回复
热议问题