Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does casting do at compiler/machine level?

I have often wondered what exactly does casting do at compiler or machine level. What does it do with the 0 and 1s in memory?

Can anyone point me at some good literature.

like image 931
uriDium Avatar asked Mar 24 '09 08:03

uriDium


1 Answers

Casting doesn't modify the individual bits when casting between reference types, it just instructs the compiler/runtime to interpret the bits in a specific way if possible.

If the cast is not possible at compile time due to incompatible types an error is issued. If the cast is not possible at runtime an exception is thrown.

The wiki page on type conversion has additional information.

like image 142
Brian Rasmussen Avatar answered Sep 21 '22 23:09

Brian Rasmussen