This Delphi code works when compiled for 32 bits, but gives an access violation when compiled for 64 bits. Is there a problem with the code, or is there a compiler bug?
{$APPTYPE CONSOLE}
uses
SysUtils;
const
MaxSize = 2; // nothing special about this value, could equally be 1
type
TArraySize = 1..MaxSize;
procedure Main;
var
size: TArraySize;
arr: array [-MaxSize..MaxSize] of Integer;
begin
FillChar(arr, SizeOf(arr), 0); // zero initialize
size := MaxSize;
Writeln(arr[-size]);
end;
begin
try
Main;
except
on E: Exception do
Writeln(E.ClassName, ': ', E.Message);
end;
Readln;
end.