Why this code segment could be compiled? With undeclared variable `PWL`?

Viewed 38
1 Answers

int PWL = PWL; does declare PWL. Though it is using the value of PWL before it is initialized, hence causes undefined behavior.

Sometimes such self referential initialization is desired, for example:

 void* ptr = &ptr;

This is completely fine. Your case is not. Compilers should warn about it. See here for how it does not compile once you enable warnings: https://godbolt.org/z/vM7KMbfvv.

Related