Watch, Follow, &
Connect with Us
Public Report
Report From: Delphi-BCB/Compiler/Delphi/Language/Dynamic Arrays    [ Add a report in this area ]  
Report #:  2148   Status: Reported
Dynamic arrays should allow low <> 0
Project:  Delphi Build #:  4.453
Version:    7.0 Submitted By:   David Marcus
Report Type:  Suggestion / Enhancement Request Date Reported:  8/21/2002 4:49:32 AM
Severity:    Serious / Highly visible problem Last Updated: 5/2/2003 12:58:35 PM
Platform:    All versions Internal Tracking #:  
Resolution: None  Resolved in Build: : None
Duplicate of:  None
Voting and Rating
Overall Rating: (7 Total Ratings)
3.43 out of 5
Total Votes: None
Description
Currently, dynamic arrays always start at 0. Static arrays do not have this restriction. Sometimes it is natural for an array to start at zero, but often it is not. In particular, many arrays would more naturally start at 1. Delphi should allow dynamic arrays to start at any integer. This can be done in such a way that the compiler can know at compile time what the starting index is. See "Steps" for a suggested syntax.
Steps to Reproduce:
var
   X: array[ 1.. ] of real;
   J: integer;
  
begin

   setlength( X, 10 );

   for J := 1 to 10 do
      X[ J ] := sqrt( J );

The syntax for open array parameters should be extended in the same way, e.g.,

procedure Clear( var X: array[ 1.. ] of real );

var
   J: integer;
  
begin

   for J := 1 to high( X ) do
      X[ J ] := 0;
Workarounds
None
Attachment
None
Comments

Ritsaert Hornstra at 8/21/2002 5:22:35 AM -
See #1861 for a discussion

David Marcus at 8/21/2002 8:16:26 PM -
This is different from 1861. This is a much smaller change. In particular, the lower index is always known at compile time so there is no effect on the speed of the code. The syntax changes are also much less than is required for 1861. This suggestion and 1861 could be implemented independently.

Server Response from: ETNACODE01