Compatible types and structures in C

后端 未结 5 1065
深忆病人
深忆病人 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 02:57

    Compatibility of structures, unions, and enumerations

    Within a single source file, each structure or union definition creates a new type that is neither the same as nor compatible with any other structure or union type. However, a type specifier that is a reference to a previously defined structure or union type is the same type. The tag associates the reference with the definition, and effectively acts as the type name. To illustrate this, only the types of structures j and k are compatible in this example:

    struct   { int a; int b; } h;
    struct   { int a; int b; } i;
    struct S { int a; int b; } j;
    struct S k;
    

    Compatible structures may be assigned to each other.

提交回复
热议问题