elements of arrays indexed by an enumerated type cannot be accessed using the enumerated type's elements
Original Reporter info from Mantis: 440bx @440bx
-
Reporter name:
Original Reporter info from Mantis: 440bx @440bx
- Reporter name:
Description:
An array such as "somevar : array[enumerated_type] of sometype" cannot be indexed using the elements of the indexing enumerated type. Refer to the simple program below to see the problem (the example does not compile but, it should - Note: Delphi compiles it without complaint.) The compiler complains on case 3, it shouldn't. Case 3 is equivalent to cases 1 and 2.
{$MODE OBJFPC }
program EnumeratedTypeArrayIndexes;
const
// ---------------------------------------------------------------------------
// case 1. using literal constants - works fine
test : array[0..1] of pwidechar = ('Dos signature',
'Offset to new executable');
a : pwidechar = @test[0]; // it really wants address of
// ---------------------------------------------------------------------------
// case 2. using named constants - works fine
_Dos_Signature = 0;
_Dos_OffsetToNewExecutable = 1;
DosFieldLabelsA : array[_Dos_Signature.._Dos_OffsetToNewExecutable]
of pwidechar =
(
'DOS signature',
'offset to new executable'
);
b : pwidechar = @DosFieldLabelsA[_Dos_Signature];
// ---------------------------------------------------------------------------
// case 3. using enumerated type constants (fully equivalent to case 2.)
//
// - should work but does not.
type
TDOS_FIELDNAMES = (
Dos_Signature, // ord = 0
Dos_OffsetToNewExecutable // ord = 1
);
const
DosFieldLabelsB : array[TDOS_FIELDNAMES]
of pwidechar =
(
'DOS signature',
'offset to new executable'
);
d : pwidechar = @DosFieldLabelsB[Dos_Signature];
begin
end.
Steps to reproduce:
compile the example program in the description.
Additional information:
Delphi compiles the sample program without problem.