Aggregate initialization, set member pointer to same struct member
问题 Is it possible to use aggregate initialization to make a pointer aptr point to a which is a member of the same struct ? struct S { int a; int* aptr; }; int main() { S s = { .a = 3, .aptr = &a //point aptr to a }; return 0; } The question is for both C and C++ . 回答1: A working initialization would be: struct S { int a; int* aptr; }; int main() { struct S s = {.a = 3, .aptr = &s.a}; printf("%d", *s.aptr); } Working samples: C11 GNU C++2a GNU Regarding the correctness of the initialization: For