[Coco] A bug in Basic09/RunB
Robert Gault
robert.gault at worldnet.att.net
Tue Dec 8 07:49:09 EST 2009
Willard and All,
Let's but this "bug" to rest. I've just spent some time reading the
manual for Basic09 and this example of parameter passing with (a+0) is
not a bug!
Basic09 performs automatic type conversions on expressions containing
mixed numerical data types. "The result is always of the same type as
the value having the largest representation, in the order: real <
integer < byte."
Basic09 passes parameters either by reference or value. Passing a
variable by reference makes it possible for the receiving procedure to
change the variable. Passing by value protects variables because the
receiving procedure can't change them. (x+0) passes a numeric value
while (x$+"") passes a string value.
Regards the "bug", you may be asking what type of data is 0? That is the
crux of the matter. 0 is an integer not a byte! Based on the above you
should expect the passed value (x+0) to be an integer regardless of how
x is defined. However, there is no need to speculate.
"The results of expressions containing numeric constants are either
integer or real values; there are no byte constants. To send byte-type
variables to a procedure, pass the values by reference. Therefore, if a
RUN statement evaluates an integer as a parameter and sends it to a
byte-type variable, the byte variable uses only the high-order byte of
the two-byte integer."
The result of x+0 is an integer because 0 is an integer making the
passed data an integer.
These quotes are from the OS-9 Owner's Manual, chapter 6 covering Basic09.
More information about the Coco
mailing list