Newsgroups: comp.lang.pascal Path: utzoo!utgpu!watserv1!maytag!watstat.waterloo.edu!dmurdoch From: dmurdoch@watstat.waterloo.edu (Duncan Murdoch) Subject: TP 6.0 compiler bug Message-ID: <1991Jan21.201226.17448@maytag.waterloo.edu> Sender: daemon@maytag.waterloo.edu (Admin) Organization: University of Waterloo Date: Mon, 21 Jan 91 20:12:26 GMT Lines: 36 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