Anonymous - 2012-11-13

Hi gang,

According to the Help file in GC Basic:

_Dim MyWord As Word
MyWord = ByteVar + AnotherByteVar

Why do this? If there are no casts, then GCBASIC will add the two values using the byte addition code, and then convert the result to a word to store in MyWord. Suppose that ByteVar is 150, and AnotherByteVar is 231. When added, this will come to 381 - which will overflow, leaving 125 in the result. However, when the cast is added, GCBASIC will treat ByteVar as if it were a word, and so will use the word addition code. This will cause the correct result to be calculated.

And yet, when I run the above, either with or without the cast, I get the correct result. It appears to me that if the variable on the left of the assignment  operator is a word, the sum of the bytes on the right is in fact carried out with word arithmetic. Am I blind to something, or is that really happening automatically?

In other words, this isn\'t a bug report necessarily, but a surprise that casting isn\'t really needed. Thanks to anyone who can clarify this.

Thomas Henry