Ray Mitchell
2009-10-28 15:54:01 UTC
Hello,
Section 5.4.1 of ISO/IEC 14882:1998(E) states:
"The result of the expression (T) cast-expression is of type T. The result
is an lvalue of T is a reference type, otherwise the result is an rvalue."
Because of this it seems to me that the statement (int)x = 5; in the
following code should result in a compiler error, but it doesn't. Obviously
I forgot to read something else somewhere in the standard, but what?
Logically, of course, one could make the case that since the typecast is to
the same type as the variable actually is, the compiler simply ignores it,
but I'm trying to justify this behavior using the language standard.
void function()
{
int x;
(int)x = 5;
}
Thanks,
Ray
Section 5.4.1 of ISO/IEC 14882:1998(E) states:
"The result of the expression (T) cast-expression is of type T. The result
is an lvalue of T is a reference type, otherwise the result is an rvalue."
Because of this it seems to me that the statement (int)x = 5; in the
following code should result in a compiler error, but it doesn't. Obviously
I forgot to read something else somewhere in the standard, but what?
Logically, of course, one could make the case that since the typecast is to
the same type as the variable actually is, the compiler simply ignores it,
but I'm trying to justify this behavior using the language standard.
void function()
{
int x;
(int)x = 5;
}
Thanks,
Ray