Reference arithmetic C works strangely. I conducted two simple experiments and it turned out that they are not calculated:
a = b->c->c->... a = &((*b)->c); Declarations of the same type name as struct T and T are different types and cause a conflict. Is this how it should be, or is my compiler defective?
gcc (Ubuntu 5.2.1-22ubuntu2) 5.2.1 20151010
#define NULL ((void*)0) typedef struct Ts * Tp; typedef struct { struct Tp c; } Ts; Ts c = {NULL}; /*1-!*/ Ts b = {&c}; /*2-!*/ Ts a = {&b}; /*3-!*/ Tp d = &a; /*4-!*/ int main(void) { Tp e = d->c->c->c; /*5-?*/ Tp * f = &d; /*6-!*/ f = &((*f)->c); /*7-?*/ f = &a.c; /*8-!*/ *f = (*f)->c; /*9-?*/ return 0; } And without a pointer declaration - even worse:
#define NULL ((void*)0) typedef struct { struct T * c; } T; T c = {NULL}; /*1-!*/ T b = {&c}; /*2-?*/ T a = {&b}; /*3-?*/ T * d = &a; /*4-!*/ int main(void) { T * e = d->c->c->c; /*5-?*/ T ** f = &d; /*6-!*/ f = &((*f)->c); /*7-?*/ f = &a.c; /*8-?*/ *f = (*f)->c; /*9-?*/ return 0; } A question mark is marked with lines with errors or warnings. Thank you in advance.
struct Tsis not declared at all. Perhaps you wanted to write - `typedef struct Ts * Tp; typedef struct Ts {Tp c; } Ts; `? Only from suchtypedefcode will not become clearer. - avp