Am 25.02.2019 um 08:09 schrieb Ondrej Pokorny:
Hello!

Implicit cast from Char/String to array of Char: is this a wanted behavior or is it a compiler bug?

(Btw. MODE DELPHI behaves the same).

program Project1;
{$mode objfpc}{$H+}
procedure A(AC: array of Char);
var
  C: Char;
begin
  for C in AC do
    WriteLn(C);
end;

procedure B(AC: array of Integer);
var
  C: Integer;
begin
  for C in AC do
    WriteLn(C);
end;

begin
  A('a');  // no error in FPC (error in Delphi)
  A('ab'); // no error in FPC (error in Delphi)
  B(1);    // error in FPC & Delphi
end.
Please note that the error for "B(1)" in FPC is misleading. If you use "B(Integer(1))" it will work. The reason is that both FPC and Delphi allow the passing of singular elements to open array parameters however Delphi does not allow constant values while FPC does.
Thus it's also clear why "A('a')" is working.
It's unclear however whether "A('ab')" is supposed to be working. I know that the compiler has some code to convert a string constant to char arrays, but I don't know if this is intended to be used here as well.

Regards,
Sven
_______________________________________________
fpc-devel maillist  -  fpc-devel@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel

Reply via email to