Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2001-05

FreePascal rudely shuts down when I try to compile this particular code

4 messages · 4 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

JONATHAN GOLD

I am having an odd problem. The following code may have bugs, but I cannot tell, as this is what keeps happening: whenever I try to compile this code ( Alt + F9 ) something flashes very fast on the screen and then FreePascal abruptly closes down! (Incidentally this code is from a tutorial I am reading, though I've changed its name.)

Program JustInCase (input, output);
        var
                invalid_operator : boolean;
                operator        : char;
                num1, num2, result : real;
        begin
                invalid_operator := FALSE;
                writeln('Enter two numbers and an operator in the format');
                writeln(' number1 operator number2');
                readln( num1 ); readln( operator ); readln( num2 );
                case operator of
                        '*' : result := num1 * num2;
					   '/' : result := num1 / num2;
                        '+' : result := num1 + num2;
                        '-' : result := num1 - num2;
                otherwise invalid_operator := TRUE;
                if invalid_operator then
                        writeln('Invalid operator')
                else
                        writeln(num1:4:2, ' ',operator,' ', num2:4:2, ' is
',result:5:2)		{this line isn't wrapped on my screen}
        end.

I have tried writing any other program, some simple calculation, and it compiles fine, giving me error messages where necessary, but it doesn't rudely shut down. But every time I try to compile the above it rudely shuts down. Is there something in this code as written that is telling it to shut down??

Thanks for any advice,

Jonathan Gold

____________________________________________________________________ Get free email and a permanent address at http://www.netaddress.com/?N=1

Carlo Kok
to JONATHAN GOLD

----- Original Message -----

Earlier message 59 lines
From: "JONATHAN GOLD" To: Cc: Sent: Sunday, May 06, 2001 11:04 PM Subject: [fpc-pascal]FreePascal rudely shuts down when I try to compile this particular code > I am having an odd problem. The following code may have bugs, but I cannot > tell, as this is what keeps happening: whenever I try to compile this code ( > Alt + F9 ) something flashes very fast on the screen and then FreePascal > abruptly closes down! (Incidentally this code is from a tutorial I am reading, > though I've changed its name.) I don't know why it abruptly closes but: > > Program JustInCase (input, output); > var > invalid_operator : boolean; > operator : char; > num1, num2, result : real; > begin > invalid_operator := FALSE; > writeln('Enter two numbers and an operator in the format'); > writeln(' number1 operator number2'); > readln( num1 ); readln( operator ); readln( num2 ); > case operator of > '*' : result := num1 * num2; > '/' : result := num1 / num2; > '+' : result := num1 + num2; > '-' : result := num1 - num2; > otherwise invalid_operator := TRUE; Otherwise is not valid Free Pascal (afaik). It should be: Else Invalid_Operator := True; end; > if invalid_operator then > writeln('Invalid operator') > else > writeln(num1:4:2, ' ',operator,' ', num2:4:2, ' is > ',result:5:2) {this line isn't wrapped on my screen} > > end. > > > I have tried writing any other program, some simple calculation, and it > compiles fine, giving me error messages where necessary, but it doesn't rudely > shut down. But every time I try to compile the above it rudely shuts down. Is > there something in this code as written that is telling it to shut down?? > > Thanks for any advice, > > Jonathan Gold >
Peter Vreman
Show quoted text 5 lines
I am having an odd problem. The following code may have bugs, but I cannot tell, as this is what keeps happening: whenever I try to compile this code ( Alt + F9 ) something flashes very fast on the screen and then FreePascal abruptly closes down! (Incidentally this code is from a tutorial I am reading, though I've changed its name.)

It's a bug in the compiler that it crashes. Please try a snapshot, that should not crash.

Show quoted text 5 lines
Program JustInCase (input, output); var invalid_operator : boolean; operator : char;

operator is a reserved keyword in FPC. You should replace it by some other name like 'oper'

Show quoted text 12 lines
num1, num2, result : real; begin invalid_operator := FALSE; writeln('Enter two numbers and an operator in the format'); writeln(' number1 operator number2'); readln( num1 ); readln( operator ); readln( num2 ); case operator of '*' : result := num1 * num2; '/' : result := num1 / num2; '+' : result := num1 + num2; '-' : result := num1 - num2; otherwise invalid_operator := TRUE;

Here a line with 'end;' is missing to terminated the case statement.

Show quoted text 7 lines
if invalid_operator then writeln('Invalid operator') else writeln(num1:4:2, ' ',operator,' ', num2:4:2, ' is ',result:5:2) {this line isn't wrapped on my screen} end.
Andrew Higgs
to JONATHAN GOLD: I am having an odd problem. The following code may have bugs, but I cannot tell, as this…

HI Jonathan,

I think it is Lazarus which is closing down abruptly not Freepascal. Have you tried to compile it by hand at the command prompt.

Kind regrads
Andrew Higgs

JONATHAN GOLD wrote 6 lines
I am having an odd problem. The following code may have bugs, but I cannot tell, as this is what keeps happening: whenever I try to compile this code ( Alt + F9 ) something flashes very fast on the screen and then FreePascal abruptly closes down! (Incidentally this code is from a tutorial I am reading, though I've changed its name.)