ron@clarity.Princeton.EDU (Ronald Beekelaar) (12/14/89)
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. The following code is not the actually code. I just typed this as an example of what the code looked like, that I tried to compile. I am using TP 5.0. ------------- Unit mycolor; Uses Crt; 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. ----------- -- ------ ron ------
jrwsnsr@nmtsun.nmt.edu (Jonathan R. Watts) (12/14/89)
In article <RON.89Dec13163843@clarity.Princeton.EDU>, 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. > >The following code is not the actually code. I just typed this as an example >of what the code looked like, that I tried to compile. I am using TP 5.0. > >------------- >Unit mycolor; > >Uses Crt; > >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. I'm not surprised it's hanging on you! You can only refer to certain BUILT-IN functions in constant declarations, not your own functions! The way your code is written, it's trying to use your "color" function before the function has been compiled! (Although I am surprised the compiler didn't catch this and give you an error.) A much better way to do it is: ... Implementation var stringcolor : byte; function color... begin stringcolor := color(blue, red); end. - Jonathan Watts jrwsnsr@jupiter.nmt.edu
dat0@rimfaxe.diku.dk (Dat-0 undervisningsassistent) (12/14/89)
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; >Interface >Function color(fore, back: byte): byte; >Implementation >Const stringcolor: byte = color(blue, red); ^^^^^^^^^^^^^^^^ This is clearly a syntax-error. According to the reference guide (v.5.5), this has to be a typed constant, which on the other hand could be a constant, an array constant, a record constant, a set constant or nil, but *not* a function call. Why it makes your compiler hang I do not know, but it shouldn't work anyway. >Function color(fore, back: byte): byte; > begin > color:= (fore and $8F) + (back and $70) > end; ------------------------------------------------------------------------- Kristian Damm Jensen (damm@rimfaxe.diku.dk) "Sex is more fun than logic. One cannot prove this, but it is, in the same way that Mount Everest is and Alma Cogan isn't." (Monty Python: 'The tape of the soundtrack of the film of the trailer of Monty Python and the Holy Grail') Kristian Damm Jensen (dat0@diku.dk) Institute of datalogi, University of Copenhagen (DIKU) Universitetsparken 1, DK-2100 Copenhagen \, Denmark
milne@ics.uci.edu (Alastair Milne) (12/15/89)
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. It crashed mine too. Specifically, the progress window was advancing its lines compiled count, when the environment's whole display was suddenly scrolled away by a mass of text (white on black, rather than the colours of the environment's display), mixing a previous editor bufferload with garbage characters. The scrolling stopped, and everything was frozen. I had to reboot. >------------- >Unit mycolor; >Uses Crt; >Interface >Function color(fore, back: byte): byte; >Implementation >Const stringcolor: byte = color(blue, red); ^^^^^ I believe this function call is illegal. I've heard of graceless error handling, but this is a new level. I wonder if the compiler is actually trying to run this function before it has even been generated. >Function color(fore, back: byte): byte; > begin > color:= (fore and $8F) + (back and $70) > end; >End. Alastair Milne
reino@cs.eur.nl (Reino de Boer) (12/15/89)
winfave@dutrun.UUCP (Alexander Verbraeck) writes: >In article <RON.89Dec13163843@clarity.Princeton.EDU> 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
dhinds@portia.Stanford.EDU (David Hinds) (12/16/89)
In article <2588590B.19990@paris.ics.uci.edu>, milne@ics.uci.edu (Alastair Milne) writes: > ron@clarity.Princeton.EDU (Ronald Beekelaar) writes: > >Const stringcolor: byte = color(blue, red); > ^^^^^ I believe this function call is illegal. The call is certainly illegal. I think only simple expressions can be evaluated in constant definitions, typed or otherwise. I think they can include compile-time internal functions (like sizeof, ord, hi, lo, ofs, seg), but nothing else, so probably not even trig functions. Since the value has to be calculated at compile-time, it would be very tricky for the compiler to use part of the program-being-compiled to evaluate it. It isn't handling the problem with much grace, though.
john@wsl.UUCP (John Allen on wsl) (12/18/89)
As far as I know you cannot assign a const in its declaration a value which is returned by a function call. -- People that don't know want to know from the people that do know and if the poeple that do know don't tell the people that don't know then the people that don't know still won't know. "Don't quote me on any issue whatsoever."
winfave@dutrun.UUCP (Alexander Verbraeck) (12/19/89)
In article <1989Dec15.080929.16028@cs.eur.nl> reino@cs.eur.nl (Reino de Boer) writes: >winfave@dutrun.UUCP (Alexander Verbraeck) writes: > >>In article <RON.89Dec13163843@clarity.Princeton.EDU> 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. >>> I can't help it, but my version of the Turbo Pascal compiler hangs. IMHO a compiler shouldn't hang, whatever stupid code you are feeding it. BTW, I indeed placed the INTERFACE statement wrongly during retyping. Of course the code of Ronald Beekelaar is illegal and not according to (T)Pascal standards, but the important point is: your compiler detects the error and mine (and the compiler of several other posters) doesn't see the error and hangs. >Reino R. A. de Boer >Erasmus University Rotterdam ( Informatica ) >e-mail: reino@cs.eur.nl ---------------------------------------------------------------------- Alexander Verbraeck e-mail: winfave@dutrun.tudelft.nl Delft University of Technology winfave@hdetud1.bitnet Department of Information Systems winfave@dutrun.uucp PO Box 356, 2600 AJ The Netherlands dutrun!winfave@hp4nl.uucp ----------------------------------------------------------------------