Sign in Join

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

Mailing lists / fpc-devel / 2003-11

Different behavior between Kylix and FPC

4 messages · 3 people ·

Reply by email Subscribe to this list Your subscription

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

Pedro Lopez-Cabanillas

Hi,

The following program behaves different in Kylix3 and FPC 1.9.

program test5;
{$IFDEF FPC}
  {$MODE DELPHI}
{$ENDIF}
var
  i: Integer;
begin
  for i:=1 to 1 do WriteLn(i);
  WriteLn(i, ' <===');
end.

$ fpc test5
Hint: End of reading config file /etc/fpc.cfg
Free Pascal Compiler version 1.9.0 [2003/11/05] for i386 Copyright (c) 1993-2002 by Florian Klaempfl
Target OS: Linux for i386
Compiling test5.pp
Linking test5
11 Lines compiled, 0.2 sec

$ ./test5
1
1 <===

$ dcc test5.pp
Borland Delphi for Linux Version 14.5 Open Edition Copyright (c) 1983,2002 Borland Software Corporation test5.pp(10) Warning: FOR-Loop variable 'i' may be undefined after loop test5.pp(12)
13 lines, 0.07 seconds, 22540 bytes code, 3088 bytes data.

$ ./test5
1
2 <===

Regards,
Pedro

ALSA Library Bindings for Pascal http://alsapas.alturl.com

Reply by email

Marco van de Voort
to Pedro Lopez-Cabanillas
The following program behaves different in Kylix3 and FPC 1.9.

And that is no problem. FPC should take the best (fastest) path. Even Kylix gives it as warning already:

test5.pp(10) Warning: FOR-Loop variable 'i' may be undefined after loop test5.pp(12)

Reply by email

Pedro Lopez-Cabanillas
to Marco van de Voort

Marco van de Voort wote:

Show quoted text 5 lines
And that is no problem. FPC should take the best (fastest) path. Even Kylix gives it as warning already: > test5.pp(10) Warning: FOR-Loop variable 'i' may be undefined after loop > test5.pp(12)

I agree that FPC behavior is right here. But Borland compilers are doing that for ages, and only recently they added a warning. I suppose they don't want to fix it for compatibility with older programs, because it would break some programs depending on that behavior.

I blame to myself because one stupid kylix program triggered this! ;-) I'm recoding it again now.

Regards,
Pedro

ALSA Library Bindings for Pascal http://alsapas.alturl.com

Reply by email

Johann Glaser
to Pedro Lopez-Cabanillas

Hi!

Show quoted text 7 lines
I agree that FPC behavior is right here. But Borland compilers are doing that for ages, and only recently they added a warning. I suppose they don't want to fix it for compatibility with older programs, because it would break some programs depending on that behavior. I blame to myself because one stupid kylix program triggered this! ;-) I'm recoding it again now.

Be especially careful when optimization is switched on. I had huge problems a few years ago with Delphi. With optimisation turned on it reversed the loop counter and counted from top downto 0.

The loop searched the maximum out of a few histogram bins. When there have been two maxima equally full it gave another result as a reference implementation (in Perl), which didn't optimize and thus always counted from 0 to Max-1. Searched a few days for that. :-(

The moral from this story: it might even happen that the last loop counter value can be the lower bound. Probably the FPC team should add a few test benches to be sure not to reverse loop counters for optimisation in some cases.

Bye
Hansi

Johann Glaser Vienna University of Technology Electrical Engineering ____ http://www.johann-glaser.at/ ____

Reply by email