Sign in Join

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

Mailing lists / fpc-pascal / 2008-04

Succ() and Pred() operations

3 messages · 3 people · –

Reply by email Subscribe to this list Your subscription

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

Ricardo Viégas

Hi there!

I have installed FPC 2.2.0 [2007/09/09] a few days ago on my WinXP-Pro-SP2, and I'm just taking a Web Tutorial on the language. when I come to "User defined variable types", I decided to make the following test:

Program Test (Output);
Type Vars = (var0, var1);
Var x : Vars;
Begin
   x := var1;
   x := Succ (x);
   Writeln ( Ord(x) );
   x := var0;
   x := Pred (x);
   Writeln ( Ord(x) );
   End.

It compiled and executed without error, and returned following 2 lines: 2
-1

Is that supposed to be the correct output, or should it have pointed an error during execution? The first symbol of the set has value "0", and second one, value "1". To which symbols corresponds the values "2" and "-1"?

Since this is my first posting, I could be on the wrong list. If that is the case, please let me know. Thanks in advance.
Best regards, Ricardo

-------------------------
Ricardo Viégas
São Paulo - SP - Brasil

Reply by email

Tomas Hajny
to Ricardo Viégas

On Wed, April 9, 2008 23:55, Ricardo Viégas wrote:

Hi Ricardo,

Show quoted text 25 lines
I have installed FPC 2.2.0 [2007/09/09] a few days ago on my WinXP-Pro-SP2, and I'm just taking a Web Tutorial on the language. when I come to "User defined variable types", I decided to make the following test: Program Test (Output); Type Vars = (var0, var1); Var x : Vars; Begin x := var1; x := Succ (x); Writeln ( Ord(x) ); x := var0; x := Pred (x); Writeln ( Ord(x) ); End. It compiled and executed without error, and returned following 2 lines: 2 -1 Is that supposed to be the correct output, or should it have pointed an error during execution? The first symbol of the set has value "0", and second one, value "1". To which symbols corresponds the values "2" and "-1"?

It ends up with runtime error 201 if compiled with range checking on (-Cr), which is a correct behaviour.

Tomas

Reply by email

Crause, Christo (JC
Show quoted text 33 lines
Message: 9 Date: Wed, 9 Apr 2008 13:55:40 -0800 From: Ricardo Vi?gas Subject: [fpc-pascal] Succ() and Pred() operations Hi there! I have installed FPC 2.2.0 [2007/09/09] a few days ago on my WinXP-Pro-SP2, and I'm just taking a Web Tutorial on the language. when I come to "User defined variable types", I decided to make the following test: Program Test (Output); Type Vars = (var0, var1); Var x : Vars; Begin x := var1; x := Succ (x); Writeln ( Ord(x) ); x := var0; x := Pred (x); Writeln ( Ord(x) ); End. It compiled and executed without error, and returned following 2 lines: 2 -1 Is that supposed to be the correct output, or should it have pointed an error during execution? The first symbol of the set has value "0", and second one, value "1". To which symbols corresponds the values "2" and "-1"?

You can enable range checking {$R+}, which should then raise an error if the value goes out of range. Tested with FPC 2.3.1.

Regards,
Christo
---------------------------------------------------------------------------- NOTICE: Please note that this eMail, and the contents thereof, is subject to the standard Sasol eMail legal notice which may be found at: http://www.sasol.com/legalnotices

If you cannot access the legal notice through the URL attached and you wish to receive a copy thereof please send an eMail to

----------------------------------------------------------------------------

Reply by email