Sign in Join

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

Mailing lists / fpc-devel / 2005-10

fpc 2.0.1 and 2.1.1 behave differently

3 messages · 2 people ·

Reply by email Subscribe to this list Your subscription

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

Vincent Snijders

Hi,

The following compiles with fpc 2.0.1, but not anymore with fpc 2.1.1.

Is it a bug in my code (and fpc 2.0.1) or in fpc 2.1.1?

program Project1;
{$mode objfpc}{$H+}
procedure test(l: longint);
begin
end;
begin
   test(longint(''));
end.

Vincent.

Reply by email

Peter Vreman
to Vincent Snijders
Show quoted text 17 lines
Hi, The following compiles with fpc 2.0.1, but not anymore with fpc 2.1.1. Is it a bug in my code (and fpc 2.0.1) or in fpc 2.1.1? program Project1; {$mode objfpc}{$H+} procedure test(l: longint); begin end; begin test(longint('')); end.

You are dependning on the internal storage of constant strings. In 2.0.1 it is an ansistring because of the $H+, compiling with $H- gives an error. Because an ansistring is 4 bytes in 32bit the explicit typeconversion to a 4 bytes longint will work in 32bit mode.

In 2.1.1 constant strings are array[0..x] of char. Where only a longint('1234') can be converted.

Reply by email

Vincent Snijders
to Peter Vreman
Peter Vreman wrote 26 lines
>Hi, > >The following compiles with fpc 2.0.1, but not anymore with fpc 2.1.1. > >Is it a bug in my code (and fpc 2.0.1) or in fpc 2.1.1? > >program Project1; > >{$mode objfpc}{$H+} > >procedure test(l: longint); >begin >end; > >begin > test(longint('')); >end. You are dependning on the internal storage of constant strings. In 2.0.1 it is an ansistring because of the $H+, compiling with $H- gives an error. Because an ansistring is 4 bytes in 32bit the explicit typeconversion to a 4 bytes longint will work in 32bit mode. In 2.1.1 constant strings are array[0..x] of char. Where only a longint('1234') can be converted.

Thanks. I suspected it had to do with this change. I just didn't know if it was a wanted or unwanted side effect of that change. I will fix my program.

Vincent.

Reply by email