Horst Kraemer said:
Your compiler uses some extension to the C language. It allows
(int)y=x because sizeof(int)==sizeof y on this platform and it refuses
(double)y=x because sizeof(double)>sizeof y on this platform.
I don't believe the sizes of the various types have anything to do
with this.
In C, a cast is not allowed on the left side of an assignment,
regardless of the types. If a cast is being used as a value (not as
an lvalue), it's legal to convert from a pointer type to an integer
type or vice versa, whether the sizes match or not. It's not legal to
convert between pointer types and floating-point types.
I would guess that the extension implemented by whatever compiler the
OP is using (allowing a cast as an lvalue) would following the same
rules. (As I vaguely alluded to earlier, I think C++ allows casts as
lvalues. I don't know the details, which aren't topical anyway.)
Note that conversions between integers and pointers, though they're
legal, are not usually meaningful. You can convert a pointer to a
sufficiently large integer type (if there is one) and back again and
get the same pointer value. Anything else will probably give you
garbage.