I wanted to see if I could initialize a global variable to point to itself:
#include <stdio.h>
struct foo { struct foo *a, *b; } x = { &x, &x };
int main()
{
printf("&x = %p, x.a = %p, x.b = %p\n", &x, x.a, x.b);
return 0;
}
This code compiles and runs as expected with gcc
(all three pointers print identically).
I want to know:
- Is this reliable?
- Is this standard?
- Is this portable?
EDIT: Just to clarify, I am questioning the availability of the address of x
in its own initializer.