[comp.lang.modula2] Bug in Top Speed

T.Moore@massey.ac.nz (T. Moore) (01/09/91)

A Possible bug in Top Speed Modula 2

The Lib.Delay function takes a CARDINAL number as its argument.
If we declare
VAR x : SHORTCARD;
and assign
    x := 50;
then the call 
    Lib.Delay(CARDINAL(250 DIV x));
delays for 5 milliseconds.
But the call
    Lib.Delay(CARDINAL(300 DIV x));
delays for less than 6 milliseconds.
The call
    IO.WrCard(CARDINAL(300 DIV x));
will explain why.

In deciding whether to represent 250 as CARDINAL or SHORTCARD, the
decision is made on the basis that it will be combined with a SHORTCARD.
The value of 300 is forced to be SHORTCARD, presumably by deleting the
first byte. (Or perhaps the division algorithm does not check that the 300
is stored as a SHORTCARD.)

Should the compiler have produced a syntax error on trying to store 300
as SHORTCARD? (Or when trying to divide a CARDINAL by a SHORTCARD).

The correct call should be
    Lib.Delay(300 DIV CARDINAL(x));
But I still think the compiler should have told me.

What do other modula2 compilers do?


-- 

Terry Moore <T.Moore@massey.ac.nz>
 Department of Mathematics and Statisics,
 Massey University, Palmerston North, New Zealand

Kroneker:  "God made the natural numbers, the rest is the work of man."
Zermelo:   "But I can construct the natural from the empty set alone."
Bystander: "Who said 'You can't get something for nothing.'?"