Possible Duplicate:
Is this self initialization valid?
Is this a well-defined C/C++ program or not?
int foo = foo;
int main()
{
}
Would foo be zero-initialized, or is it undefined behaviour?
It is an ill-formed C program. In C initializers for objects with static storage duration must be constant expressions. The foo on the right-hand side is not a constant expression.
In C++ it is well-formed and has defined behavior, because of zero-initialization of objects with static storage duration (which takes place before any other initialization).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With