[fpc-devel] Scalar value is accepted as an argument for an openarray parameter

Sven Barth pascaldragon at googlemail.com
Sun Jun 10 18:23:33 CEST 2012


On 10.06.2012 00:22, Skybuck Flying wrote:
> 
> 
> -----Original Message----- From: Marc Weustink
> Sent: Friday, June 08, 2012 9:08
> To: FPC developers' list
> Subject: Re: [fpc-devel] Scalar value is accepted as an argument for an 
> openarray parameter
> 
> On 8-6-2012 8:18, Alexander Klenin wrote:
>> The following code compiles both with :
>>
>> procedure F(const A: array of ShortInt); begin end;
>> begin F(1); end.
>>
>> I think this is a bug in FPC, but if not -- it should be documented here:
>> http://freepascal.org/docs-html/ref/refsu59.html#x157-16700014.4.5
>>
>> I am willing to file an issue one way or another.
> 
> "
> Unfortunately Delphi (6) accepts this too. It took me some time at work
> "
> 
> Delphi XE2 does not ;)

Delphi XE does not accept constants either, but scalar variables. So the
following compiles:

=== source begin ===

program openarrayscalar;

{$apptype console}

procedure Test(aArgs: array of LongInt);
var
  i: LongInt;
begin
  for i in aArgs do
    Writeln(i);
end;

var
  z: LongInt;
begin
  z := 42;
  Test(z);
  Readln;
end.

=== source end ===

The Delphi help also mentions this here:
http://docwiki.embarcadero.com/RADStudio/en/Parameters_%28Delphi%29#Open_Array_Parameters

=== qoute begin ===

Instead of an array, you can pass a variable of the open array
parameter's base type. It will be treated as an array of length 1.

=== qoute end ===

Constant values and untyped constants can indeed not be used as argument
for open array parameters, but typed constants can.

Regards,
Sven



More information about the fpc-devel mailing list