Why does Max compiles this piece of code?
BlitzMax Forums/BlitzMax Programming/Why does Max compiles this piece of code?
| ||
What is Max doing here?Local i:Byte i = 3000 Print i ...it prints out 184. Now I know that 3000 is larger than what a Byte can handle. I just want to know why it printed out 184 instead of crashing or compiling for that matter. Edit: Ok I know why it compiled, so why the output instead of a crash? This could be very to debug if you're not careful when programming. And one cool thing about vb.net is that it won't even let you compile. It says 'Constant expression is not representable in type Byte.' |
| ||
I supouse it truncates data without any out of bounds check. This could be done to increase run-time speed. Avoid a 'out of range' check in absolutely every asignment can increase a lot the run-time performance. |
| ||
3000 = bb8 in hex. You i var is a byte..so it reads the var as b8...that are equal to 184. I may be wrong....:) Regards Sveinung |
| ||
You can do that in C, C++ and Delphi to.. The compiler usually issues a warning that the assignment is out of range / truncation will occur, but it is legal. I believe C# will fail to compile. Cheers, Stu |
| ||
Truncage. |