Is this valid C? No warning about p being uninitialized

Viewed 399

Compiling this code snippet with gcc (4.5) and as many -Wall, -Wextra, -Wuninitialized type flags turned on as possible gives me no warnings:

int main() {
    int *p = p;
    printf("p = %p\n", (void *)p);
    return 0;
}

But running it multiple times gives this output:

p = 0xbe9ff4
p = 0x550ff4
p = 0xeb1ff4
p = 0x4caff4

... and so on.

What's going on here?

EDIT: Compiling with "g++ -Wall" instead gives me warning as I'd expect:

In function ‘int main()’: warning: ‘p’ is used uninitialized in this function
2 Answers
Related