Fun with numbers - dammit, but I want a cast!

Erik Max Francis max at
Mon Aug 11 20:15:30 CEST 2003

Terry Reedy wrote:

> No, quite different.  A C cast (at least usually) recasts a block of
> bits in a new role without changing the bits.  Type constructors
> (unless redundant as in int(1)) return a different object with a
> different set of bits.

Well, the issue is that, in C, a cast can mean a lot of different
things.  That's why, in C++, casts are separated into template like
syntaxes depending on their purpose.  The unsafe form of C cast is a
reinterpret_cast in C++, and sometimes a const_cast (if you actually
cast away constness of a truly const object and then attempt to mutate
it).  The other two -- static_cast and dynamic_cast -- are "safe" in the
sense of being well-defined when the compiler accepts them, and merely
invoke a well-defined conversion and do a runtime type cast,

   Erik Max Francis && max at &&
 __ San Jose, CA, USA && 37 20 N 121 53 W && &tSftDotIotE
/  \ Nobody can reach me, nobody can touch me; it's a wonderful feeling.
\__/  Aaliyah

More information about the Python-list mailing list