Depending on what you want to do, either writeln("sqrt(-1)"); or writeln(sqrt(1)); works.
I'm sorry, I haven't made it clear the first time. So: With CRT, all writeln do nothing. For example: uses crt; begin writeln('OK') end. produces nothing. uses crt; begin writeln('OK'); writeln(sqrt(-1)) end. produces just the error message from sqrt(-1), NOT 'OK'. Same programs without "uses crt;" both include 'OK' (the latter before the error message).
You might try:
program testcrt; uses gpc, crt; begin writeln('OK'); sleep(10); writeln(sqrt(-1)); end.
Now I understand more about the problem. If I put the CRT unit in, each write will actually be to some virtual screen appearing on top of my console and disappearing after program finished. As all test programs above finish quickly, I simply can't see it. Therefore, this sample:
program testcrt; uses gpc, crt; begin writeln('OK'); readln end.
works as expected, but there is nothing left on the console after it ran. Is this by design? Because I might have programs which use CRT for every kind of things and I still must see their output.
On 25 Jan 2009 at 0:11, Alexey Kotlyarov wrote:
[...]
program testcrt; uses gpc, crt; begin writeln('OK'); readln end.
works as expected, but there is nothing left on the console after it ran. Is this by design?
Yes. That is the whole point of what Frank has been trying to explain.
Best regards, The Chief -------- Prof. Abimbola A. Olowofoyeku (The African Chief) web: http://www.greatchief.plus.com/
Alexey Kotlyarov wrote:
Now I understand more about the problem. If I put the CRT unit in, each write will actually be to some virtual screen appearing on top of my console and disappearing after program finished.
Though technically not 100% correct, that's a way to imagine it. BTW, if you use the X11 version of PDCurses (install PDCurses and compile with "-DX11"), it will open its own X11 window and do all CRT I/O there. In this case, it's quite obvious that all output will disappear when the program finishes.
What to do about it depends on what you really want to achieve (which I can't tell from the small example, of course). If you want to keep the last screen from CRT after terminating the program, that's not directly possible with CRT (and even if it were, it wouldn't be recommended, since X11 terminals are switched to an "alternate mode" for CRT, and continuing in this mode for regular I/O afterward has some strange effects).
What I wanted to achieve was just compiling old BP things which use CRT for almost no reason (such as "clrscr" in the start or "delay" somewhere). However, with all this, I will just remove the uses directive. Thanks for the clarifications!
Yes, that's what I'd suggest. Instead of "Delay" use can use "Sleep" (seconds) or "SleepMicroSeconds" (microseconds). You need "uses GPC" for both.
Yang Lao wrote:
There's a lot of historical-baggage connected with the crt unit, especially the notorious Runtime error 200 issue.
Only in the BP version. I didn't actually emulate this bug in GPC. ;-)
Frank