Path: utzoo!attcan!utgpu!jarvis.csri.toronto.edu!cs.utexas.edu!uunet!mcsun!hp4nl!eurtrx!euraiv1!reino From: reino@cs.eur.nl (Reino de Boer) Newsgroups: comp.lang.pascal Subject: Re: TP bug??? Message-ID: <1989Dec15.080929.16028@cs.eur.nl> Date: 15 Dec 89 08:09:29 GMT References: <1033@dutrun.UUCP> Distribution: comp Organization: Erasmus Universiteit Rotterdam, dept. CS (Informatica) Lines: 92 winfave@dutrun.UUCP (Alexander Verbraeck) writes: >In article ron@clarity.Princeton.EDU (Ronald Beekelaar) writes: >> >>I was trying to compile the following TP code, but everytime the compiler hang >>and even ctrl-break didn't work anymore. I had to reboot the computer. >> >>Unit mycolor; >>Uses Crt; My copy of Turbo Pascal gives (as expected) the following compiler error: INTERFACE expected. >>Interface >>Function color(fore, back: byte): byte; >>Implementation >>Const stringcolor: byte = color(blue, red); >>Function color(fore, back: byte): byte; >> begin >> color:= (fore and $8F) + (back and $70) >> end; >>End. The following (though syntactically correct) still generates a compiler error (as expected by anyone who read the manual): unit mycolor; interface uses crt; function color( fore, back : byte ) : byte; implementation const stringcolor : byte = color( blue, red ); { ^ } { Compiler error: cannot evaluate this expression } function color( fore, back : byte ) : byte; begin color := ( fore and $8F ) + ( back and $70 ) end; end. >It looks like a real bug. It isn't. >I tried to compile the code using TP 5.5 and >PANG, the compiler hang. What strange version of Turbo Pascal are you using ? >The strange thing is, that the line counter >shows 0 lines compiled. When you introduce a bug, the bug is correctly >reported and the compiler does not hang. The bug is independent of the >name 'color'. To try it in a quick way, I used a's, b's and c's and the >same error occurred..... strange..... >The following program DOES compile, but stops your computer when it is >runned. >program test; >uses Crt; >function abc:byte; >begin > abc:=1; >end; >const sc=abc; >begin > writeln; >end. It doesn't (and shouldn't) compile at all. I refer to pages 15--16 of the Turbo Pascal (R) Reference Guide (Version 5.0 and 5.5): Since the compiler has to be able to completely evaluate a constant expression at compile time, the following constructs are {\it not\/} allowed in constant expressions: . . o function calls (except those noted in the following text) . . The following standard functions are allowed in constant expressions: abs, ...., trunc and as expected, no user defined functions here. Reino -- Reino R. A. de Boer Erasmus University Rotterdam ( Informatica ) e-mail: reino@cs.eur.nl