Sign in Join

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

Mailing lists / fpc-devel / 2010-01

unexpected results with succ() and fpc 2.4.0

9 messages · 4 people · –

Reply by email Subscribe to this list Your subscription

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

Stefan Kisdaroczi

hi list,

the code below compiled and worked with fpc 2.2.x. With fpc 2.4.0 compilation fails with "Division by zero".

---- 8< ----
program divsucc;
begin
  writeln( 256 DIV succ(255) );
end.
---- 8< ----

Free Pascal Compiler version 2.4.0 [2009/12/18] for i386 Copyright (c) 1993-2009 by Florian Klaempfl
Target OS: Win32 for i386
Compiling divsucc.pas
divsucc.pas(4,16) Error: Division by zero
divsucc.pas(7) Fatal: There were 1 errors compiling module, stopping Fatal: Compilation aborted

Comments? Hints?

kisda

Reply by email

Michael Van Canneyt
to Stefan Kisdaroczi
Stefan Kisdaroczi wrote 11 lines
hi list, the code below compiled and worked with fpc 2.2.x. With fpc 2.4.0 compilation fails with "Division by zero". ---- 8< ---- program divsucc; begin writeln( 256 DIV succ(255) ); end.

Well, Succ(255) is probably evaluated as a byte, in which case it is zero, and then when attempting to evaluate the DIV, the compiler indeed tries to divide by zero.

I don't know whether the behaviour of the compiler changed in this respect, but it seems so ?

Michael.

Reply by email

Jonas Maebe
to Stefan Kisdaroczi: the code below compiled and worked with fpc 2.2.x. With fpc 2.4.0 compilation fails with…
Stefan Kisdaroczi wrote 17 lines
---- 8< ---- program divsucc; begin writeln( 256 DIV succ(255) ); end. ---- 8< ---- Free Pascal Compiler version 2.4.0 [2009/12/18] for i386 Copyright (c) 1993-2009 by Florian Klaempfl Target OS: Win32 for i386 Compiling divsucc.pas divsucc.pas(4,16) Error: Division by zero divsucc.pas(7) Fatal: There were 1 errors compiling module, stopping Fatal: Compilation aborted Comments? Hints?

It's a compiler bug that got triggered by another fix. You can work around it for now by using something like "256 DIV succ(longint(255))"

Jonas

Reply by email

Stefan Kisdaroczi
to Jonas Maebe
Jonas Maebe wrote 23 lines
On 04 Jan 2010, at 14:07, Stefan Kisdaroczi wrote: > ---- 8< ---- > program divsucc; > > begin > writeln( 256 DIV succ(255) ); > end. > ---- 8< ---- > > Free Pascal Compiler version 2.4.0 [2009/12/18] for i386 > Copyright (c) 1993-2009 by Florian Klaempfl > Target OS: Win32 for i386 > Compiling divsucc.pas > divsucc.pas(4,16) Error: Division by zero > divsucc.pas(7) Fatal: There were 1 errors compiling module, stopping > Fatal: Compilation aborted > > Comments? Hints? It's a compiler bug that got triggered by another fix. You can work around it for now by using something like "256 DIV succ(longint(255))"

Thanks for the fast reply. No Problem to work around this one, but there are 1788 succ() calls :-o in our applications :-) That was the only one that did not compile. All others did compile, but some of them will probably not work.

If its considered a bug i'm fine. Is there already a bugtracker id? Should i add a bugreport?

kisda

Reply by email

Jonas Maebe
to Stefan Kisdaroczi
Stefan Kisdaroczi wrote
Thanks for the fast reply. No Problem to work around this one, but there are 1788 succ() calls :-o in our applications :-) That was the only one that did not compile. All others did compile, but some of them will probably not work.

The problem is only with integer constants. It's however quite insidious since even enabling range or overflow checking doesn't catch this compiler error.

If its considered a bug i'm fine. Is there already a bugtracker id? Should i add a bugreport?

A bug report is not necessary, I've just fixed it in svn trunk.

Jonas

Reply by email

Stefan Kisdaroczi
to Jonas Maebe
Jonas Maebe wrote 16 lines
On 04 Jan 2010, at 14:49, Stefan Kisdaroczi wrote: > Thanks for the fast reply. No Problem to work around this one, but > there are 1788 succ() calls :-o in our applications :-) > That was the only one that did not compile. All others did compile, > but some of them will probably not work. The problem is only with integer constants. It's however quite insidious since even enabling range or overflow checking doesn't catch this compiler error. > If its considered a bug i'm fine. Is there already a bugtracker id? > Should i add a bugreport? A bug report is not necessary, I've just fixed it in svn trunk.

Thank you very much. I should really try the release candidates next time... sorry

kisda

Reply by email

Stefan Kisdaroczi
to Stefan Kisdaroczi: Thank you very much. I should really try the release candidates next time... sorry kisda
Stefan Kisdaroczi wrote 17 lines
Am 04.01.2010 16:13, schrieb Jonas Maebe: > > On 04 Jan 2010, at 14:49, Stefan Kisdaroczi wrote: > >> Thanks for the fast reply. No Problem to work around this one, but >> there are 1788 succ() calls :-o in our applications :-) >> That was the only one that did not compile. All others did compile, >> but some of them will probably not work. > > The problem is only with integer constants. It's however quite insidious > since even enabling range or overflow checking doesn't catch this > compiler error. > >> If its considered a bug i'm fine. Is there already a bugtracker id? >> Should i add a bugreport? > > A bug report is not necessary, I've just fixed it in svn trunk.

This fix is missing in the fixes_2_4 branch. Please consider merging. Thanks. trunk: r14537

kisda

Show quoted text 10 lines
Thank you very much. I should really try the release candidates next time... sorry kisda _______________________________________________ fpc-devel maillist - http://lists.freepascal.org/mailman/listinfo/fpc-devel

Reply by email