dmurdoch@watstat.waterloo.edu (Duncan Murdoch) (01/22/91)
A bug I just saw mentioned on Compuserve: var v : word; const c : word = 23; b1 : word = c; { This won't end up as 23 } b2 : word = v; { This doesn't even make sense, but it'll compile. } begin writeln('b1=',b1); writeln('b2=',b2); end. Neither b1 nor b2 is a legal typed constant declaration, according to the language spec, because neither c nor v is a constant expression. If you made them into untyped constant declarations, the compiler would catch the error, but it doesn't here. I don't think the bug of allowing constants to be declared equal to variables is very serious, because it doesn't make any sense anyways. But it's a pretty common mistake to think that the b1 declaration is legal, and that b1 ends up initialized to 23. (In fact, I think it should be legal, but that's another story.) The fact that b1 ends up with garbage in it (0 in my runs) is likely to introduce terribly hard to find bugs into programs. This bug was discovered by someone who was getting mysterious error 207s (invalid floating point operations), and it turned out to be because a floating point constant didn't get initialized properly. Hope this is of interest to someone! Duncan Murdoch dmurdoch@watstat.waterloo.edu
reino@cs.eur.nl (Reino de Boer) (01/23/91)
dmurdoch@watstat.waterloo.edu (Duncan Murdoch) writes: >A bug I just saw mentioned on Compuserve: >var > v : word; > >const > c : word = 23; > > b1 : word = c; { This won't end up as 23 } > b2 : word = v; { This doesn't even make sense, but it'll compile. } BTW. TP 5.X will give a compiler error 133: Cannot evaluate expression for both the bx declarations. Reino -- Reino R. A. de Boer "We want to build the right product right, right?" Erasmus University Rotterdam ( Informatica ) e-mail: reino@cs.eur.nl