[fpc-pascal] fpc has trouble with array types
Sven Barth
pascaldragon at googlemail.com
Tue Oct 18 11:12:34 CEST 2011
Am 18.10.2011 05:47, schrieb Andrew Pennebaker:
> But, but, the docs imply that this is the syntax for a function that
> returns an array of bytes.
[snip]
> function XlatPrime () : array of byte;
> begin
> XlatPrime := (
> $64, $73, $66, $64, $3b, $6b, $66, $6f,
> $41, $2c, $2e, $69, $79, $65, $77, $72,
> $6b, $6c, $64, $4a, $4b, $44, $48, $53,
> $55, $42, $73, $67, $76, $63, $61, $36,
> $39, $38, $33, $34, $6e, $63, $78, $76,
> $39, $38, $37, $33, $32, $35, $34, $6b,
> $3b, $66, $67, $38, $37
> );
> end;
Free Pascal (and Delphi and TP) does not support such syntax. I suggest
you that you define your array as a const instead of a function and just
use that.
E.g.
const
XlatPrime: array[0..52] of Byte = (
$64, $73, $66, $64, $3b, $6b, $66, $6f,
$41, $2c, $2e, $69, $79, $65, $77, $72,
$6b, $6c, $64, $4a, $4b, $44, $48, $53,
$55, $42, $73, $67, $76, $63, $61, $36,
$39, $38, $33, $34, $6e, $63, $78, $76,
$39, $38, $37, $33, $32, $35, $34, $6b,
$3b, $66, $67, $38, $37
);
It is necessary to specify the element count correctly.
Note: In trunk you should be able to do the following:
type
TByteArray = array of Byte;
function XlatPrime(): TByteArray;
begin
XlatPrime := TByteArray.Create(
$64, $73, $66, $64, $3b, $6b, $66, $6f,
$41, $2c, $2e, $69, $79, $65, $77, $72,
$6b, $6c, $64, $4a, $4b, $44, $48, $53,
$55, $42, $73, $67, $76, $63, $61, $36,
$39, $38, $33, $34, $6e, $63, $78, $76,
$39, $38, $37, $33, $32, $35, $34, $6b,
$3b, $66, $67, $38, $37
);
end;
This feature was introduced because of Delphi compatibilty (and I still
have the opinion that it would be nice if that would be extended for
"unnamed" array types as well...)
Regards,
Sven
More information about the fpc-pascal
mailing list