Anshul Singhal wrote:
there is a concept of narrowing in automatic typecasting which states that if a larger type can be assigned to smaller type with a loss of information for e.g float can be assigned to int with the loss of decimal part. Why can't the same thing happen here??
First, let's clean up the terminology a bit. Implicit casting is probably what you meant -- and not automatic typecasting. Second, the concept that you are referring to are the special rules related to compile time constants.... Anyway, to answer your question.
To be considered as a compile time constant, strict rules must be adhered to. In this case, neither the variables y or z are compile time constants (although they have been assigned compile time constants). Hence, the expression is not a compile time constant, and hence, the rule doesn't apply.
And about the rule, the implicit casting rule is defined as part of the assignment conversion portion of the specification (section 5.2). And in the part about compile time constants... the value to be assigned must be of type byte, char, short, or int. This is not true in this case, even if the expression were a compile time constant.
Henry