"as" keyword woes

Aaron Brady castironpi at gmail.com
Sun Dec 7 06:26:08 EST 2008


On Dec 6, 9:35 pm, Carl Banks <pavlovevide... at gmail.com> wrote:
> On Dec 6, 8:17 pm, Steven D'Aprano <st... at REMOVE-THIS-
> > I don't like "cast", because a cast is an instruction to the compiler to
> > treat data as some type other than what it was defined as.
> It doesn't
> > create a new piece of data. (At least in C-like languages.)
>
> Actually, C-like languages do exactly that.  (float)i doesn't take the
> bits of int i and treat them as if they were a float, it creates new
> data in the appropriate data type that matches the value of i
> semantically, which would have a very different bit pattern.

'(float&) i' does what he said.

	int i;
	float& f= ( (float&) i );
	f= 1;
	printf( "%x %f\n", i, f );

/Output:

3f800000 1.000000

Sorry for the tangent.



More information about the Python-list mailing list