I am simultanously reporting this bug to Borlands bug page, to the
Delphi Bug List, and to the newgroups comp.lang.pascal.delphi.misc and
borland.public.delphi.objectpascal.
Description:
============
When declaring the constant
Const MaxDim = High(Cardinal);
in a unit one gets a fatal compiler error of the type:
Fatal Error: C:\PAS\error\BugUnit.PAS(12): Internal error: URW376.
If one continues to try different recompiles, one periodically gets the
error:
Access violation at address 0080D233 in module 'DCC.DLL'. Read of
address FFFFFFFF.
This is found using Delphi Professional 3.0 (Build 5.53), both with the
IDE compiler and the command-line compiler. The machine was a Toshiba
730CDT with 48MB ram running Windows95.
Workaround:
===========
1. Use Integer instead:
Const MaxDim = High(Integer);
2. Give the constant an explicit type, e.g:
Const MaxDim:Cardinal = High(Cardinal);
Const MaxDim:Integer = High(Cardinal);
3. Reduce the constant by one:
Const MaxDim = High(Cardinal)-1;
4. Declare the constant in the program (*.dpr) file.
Background:
===========
This bug is probably the same as the one reported as "Compiler error
URW376" by Pelle F.S. Liljendal and Stefan Hoffmeister at the Delphi 3.0
Bug List at
http://www.dataweb.nl/~r.p.sterkenburg/bugs3/compiler.htm
I have earlier reported this bug to the Borland bug page at
http://www.borland.com/devsupport/bugs/bug_reports.html
but had then not been able to track down the cause. After several
reinstallations of D3, I had to revert to D2 to get my work done.
Narrowing down the circumstances of the bug was no easy task (Borland, I
should be paid for this!), but the closest I could get was declaring the
constant alone in a unit, as seen in the example below.
The bug is easy to work around, but as the error message is of no help,
identyfing it can be a major problem. The problem is real as the use of
a very big constant facilitates declerations of dynamic arrays of the
type
Type SomeArray=Array[1..(MaxDim Div SizeOf(SomeElement)] of
SomeElement;
without having to turn of rangechecking for other variables.
Example:
========
The state of compiler directives was not found to have any effect but is
included for reference.
{$A+,B-,C-,D-,E-,F-,G+,H+,I-,J+,K-,L-,M-,N+,O+,P+,Q-,R-,S-,T-,U-,V+,W+,X+,Y-,Z1}
{$MINSTACKSIZE $00004000}
{$MAXSTACKSIZE $00100000}
{$IMAGEBASE $00400000}
{$APPTYPE CONSOLE}
Programme with bug, two files, a DPR-file and a unit PAS-file:
=====================BugPr.dpr==================
program BugPr;
uses
BugUnit in 'BugUnit.pas';
procedure Go;
Begin
Writeln(MaxDim);
end;
begin
Go;
end.
=====================BugPr.dpr==================
=====================BugUnit.pas================
unit BugUnit;
interface
Const MaxDim = High(Cardinal);
implementation
end.
=====================BugUnit.pas================
Programme without bug, exactly the same, except the Const decleration is
moved to the DPR-file (so no unit PAS-file):
=====================NoBugPr.dpr================
program NoBugPr;
Const MaxDim = High(Cardinal);
procedure Go;
Begin
Writeln(MaxDim);
end;
begin
Go;
end.
=====================NoBugPr.dpr================
--
Sverre A.C. Kittelsen
Research Economist/Forsker e-mail: s.a.c.kittel...@snf.uio.no
SNF Oslo tel.: +47-22958815
Gaustadalleen 21 fax: +47-22958825
N-0371 Oslo, Norway priv.: +47-67141662
========================================================================
Stiftelsen for samfunns- og n?ringslivsforskning, Avd Oslo
Foundation for research in economics and business administration, Oslo