Re: question about cast
From: Keith Thompson (kst-u_at_mib.org)
Date: 01/16/04
- Next message: Ç㼺¿í: "Re: [OT] Re: Detailed Re: Question: Unicode <-> HEX conversion in C source file?"
- Previous message: Peter Nilsson: "Re: question about cast"
- In reply to: Horst Kraemer: "Re: question about cast"
- Next in thread: Richard Bos: "Re: question about cast"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Thu, 15 Jan 2004 23:45:06 GMT
Horst Kraemer <horst.kraemer@epost.de> writes:
[...]
> 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.
-- Keith Thompson (The_Other_Keith) kst-u@mib.org <http://www.ghoti.net/~kst> San Diego Supercomputer Center <*> <http://www.sdsc.edu/~kst> Schroedinger does Shakespeare: "To be *and* not to be"
- Next message: Ç㼺¿í: "Re: [OT] Re: Detailed Re: Question: Unicode <-> HEX conversion in C source file?"
- Previous message: Peter Nilsson: "Re: question about cast"
- In reply to: Horst Kraemer: "Re: question about cast"
- Next in thread: Richard Bos: "Re: question about cast"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|