If you use a binary operator on an integer type, the compiler decides the common type between the left and right type, that is the smallest type that can handle both the left and right operand. I.e. the common type of "0..99" and "byte" is 0..255. The common type of "integer" and "word" is -32768..65535.Originally Posted by PP2005
Before doing the operation, the compiler converts both operands to the common type. Then the compiler does the operation.
Assume random(40) returns 35. On the left side there is a constant, and on the right side there is a word. The smallest type that can handle both 20 and a word is 0..65535. So, 20 is "converted" to 0..65535, and 35 is "converted" to 0..65535. Then the compiler subtracts: 20-35=-15. -15 is not in the range of the common type 0..65535, therefore, you have an arithmetic overflow.
Bookmarks