Sign in Join

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

Mailing lists / fpc-pascal / 2003-01

compiler bug?

6 messages · 3 people · –

Reply by email Subscribe to this list Your subscription

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

Mark Emerson

The following program compiles but crashes with an integer range error when it gets to the comparison:

{$R+}
var
  a : cardinal;
  b : longint;
begin
  a := 0;
  b := -1;
  if a > b then writeln ('OK');
end.

Am I missing something, or is this a compiler bug?

Mark

Reply by email

Florian Klaempfl
to Mark Emerson
Mark Emerson wrote 14 lines
The following program compiles but crashes with an integer range error when it gets to the comparison: {$R+} var a : cardinal; b : longint; begin a := 0; b := -1; if a > b then writeln ('OK'); end. Am I missing something, or is this a compiler bug?

Compile with warnings on, i.e. -vw .

Reply by email

Peter Vreman
to Mark Emerson: The following program compiles but crashes with an integer range error when it gets to…
Show quoted text 14 lines
The following program compiles but crashes with an integer range error when it gets to the comparison: {$R+} var a : cardinal; b : longint; begin a := 0; b := -1; if a > b then writeln ('OK'); end. Am I missing something, or is this a compiler bug?

This is a bug. Added it as tb0447 to the testsuite.

Workaround is to use int64(a) in the comparison

Reply by email

Mark Emerson
to Peter Vreman
Peter Vreman wrote 19 lines
> The following program compiles but crashes with an integer range error > when it gets to the comparison: > > {$R+} > var > a : cardinal; > b : longint; > begin > a := 0; > b := -1; > if a > b then writeln ('OK'); > end. > > Am I missing something, or is this a compiler bug? This is a bug. Added it as tb0447 to the testsuite. Workaround is to use int64(a) in the comparison

OK, int64 works around that one....but what about this one, which crashes on the call to inc (I guess inc can't handle a 64 bit parameter):

{$R+}
var
  a : ansistring;
  b : cardinal;
begin
  a := 'hello';
  b := -1;
  inc (b, int64(length (a)));
end.

Reply by email

Peter Vreman
to Mark Emerson
Show quoted text 33 lines
Peter Vreman wrote: > > > The following program compiles but crashes with an integer range error > > when it gets to the comparison: > > > > {$R+} > > var > > a : cardinal; > > b : longint; > > begin > > a := 0; > > b := -1; > > if a > b then writeln ('OK'); > > end. > > > > Am I missing something, or is this a compiler bug? > > This is a bug. Added it as tb0447 to the testsuite. > > Workaround is to use int64(a) in the comparison OK, int64 works around that one....but what about this one, which crashes on the call to inc (I guess inc can't handle a 64 bit parameter): {$R+} var a : ansistring; b : cardinal; begin a := 'hello'; b := -1; inc (b, int64(length (a))); end.
the b:=-1 is not valid. The 1.1 compiler gives a correct error for it:
p.pp(7,8) Error: range check error while evaluating constants

Reply by email

Florian Klaempfl
to Peter Vreman: This is a bug. Added it as tb0447 to the testsuite. Workaround is to use int64(a) in the…
Peter Vreman wrote 18 lines
The following program compiles but crashes with an integer range error when it gets to the comparison: {$R+} var a : cardinal; b : longint; begin a := 0; b := -1; if a > b then writeln ('OK'); end. Am I missing something, or is this a compiler bug? This is a bug. Added it as tb0447 to the testsuite.

It isn't considered as a bug in 1.0.x, see also my message about the warning.

Workaround is to use int64(a) in the comparison

Reply by email