I want to initialize a const variable using an if-else.
For example:
const int foo;
if (bar) {
foo = 1;
} else {
foo = 2;
}
In Java, this is legal code (using final instead of const). The reason is that in all possible outcomes, the variable is assigned once and never reassigned. In C, this is not legal code. What is the reason that it can't be legal code in C?