Problems with the Ads of an Array

Product Version(s): 3.31
Operating System:   MS-DOS
Flags: ENDUSER | buglist3.31 fixlist4.00
Last Modified:  4-OCT-1988    ArticleIdent: Q11585

Under the following conditions, incrementing the index by one fails:

1. A field of a record is an ads of an array.
2. Another field is the index to the array.
3. The array is allocated on the long heap.
4. The record is passed by VARS and the array is referenced.

The program adstest2.PAS (below) demonstrates this behavior. The
record variable BUFFER is passed to Procedure Increment by VARS. The
statement labeled "instruction 1" references the elements of the
array. "Instruction 2" increments the array's index (BUFFER.CUR).
However, BUFFER.CUR is not being incremented, as can be seen by
running the program. "Instruction 3" prints the unincremented index.
Microsoft is researching this problem and will post new information as
it becomes available.

Microsoft has confirmed this to be a problem in Version 3.31. This
problem was corrected in Version 4.00.

The following notes apply:

1. Delete the statement labeled "Instruction 1" and the program
   works successfully (see adstest3.PAS).

2. Use BUFFER as a global variable rather than passing it to
   Procedure Increment by VARS, and the program works successfully
   (see adstest1.PAS).

3. adstest2.PAS works successfully under Pascal Version 3.20.

The following are short example codes:

Short Example Code: adstest1.pas

    program test(input,output);
    type    ads_table=ads of array[1..32766] of char;
            buffer_typ=record
                            TABLE_ADS:ads_table;
                            CUR:integer;
                            FINISH:integer;
                       end;

    const   size=200;

    VAR     BUFFER:buffer_typ;
            CH:char;

    FUNCTION ALLMQQ(WANTS:word):adsmem;extern;

    procedure initialize_buffer;
    begin
            BUFFER.TABLE_ADS:=allmqq(size);
            BUFFER.FINISH:=size;
            BUFFER.CUR:=1;
    end;

    procedure increment;
    begin
      repeat
            CH:=buffer.table_ads^[buffer.cur];     {instruction 1}
            BUFFER.CUR:=buffer.cur + 1;            {instruction 2}
            WRITELN('BUFFER.CUR = ',BUFFER.CUR:1); {instruction 3}
      until (buffer.cur > buffer.finish);
    end;

    begin {main}
            initialize_buffer;
            increment;
    end.

Short Example Code:  adstest2.pas

    program test(input,output);
    type    ads_table=ads of array[1..32766] of char;
            buffer_typ=record
                            TABLE_ADS:ads_table;
                            CUR:integer;
                            FINISH:integer;
                       end;

    const   size=200;

    VAR     BUFFER:buffer_typ;
            CH:char;

    FUNCTION ALLMQQ(WANTS:word):adsmem;extern;

    procedure initialize_buffer;
    begin
            BUFFER.TABLE_ADS:=allmqq(size);
            BUFFER.FINISH:=size;
            BUFFER.CUR:=1;
    end;

    PROCEDURE INCREMENT(VARS BUFFER:buffer_typ);
    begin
      repeat
            CH:=buffer.table_ads^[buffer.cur];     {instruction 1}
            BUFFER.CUR:=buffer.cur + 1;            {instruction 2}
            WRITELN('BUFFER.CUR = ',BUFFER.CUR:1); {instruction 3}
      until (buffer.cur > buffer.finish);
    end;

    begin {main}
            initialize_buffer;
            increment(buffer);
    end.

Short Example Code: adstest3.pas

    program test(input,output);
    type    ads_table=ads of array[1..32766] of char;
            buffer_typ=record
                            TABLE_ADS:ads_table;
                            CUR:integer;
                            FINISH:integer;
                       end;

    const   size=200;

    VAR     BUFFER:buffer_typ;
            CH:char;

    FUNCTION ALLMQQ(WANTS:word):adsmem;extern;

    procedure initialize_buffer;
    begin
            BUFFER.TABLE_ADS:=allmqq(size);
            BUFFER.FINISH:=size;
            BUFFER.CUR:=1;
    end;

    PROCEDURE INCREMENT(VARS BUFFER:buffer_typ);
    begin
      repeat
            BUFFER.CUR:=buffer.cur + 1;            {instruction 2}
            WRITELN('BUFFER.CUR = ',BUFFER.CUR:1); {instruction 3}
      until (buffer.cur > buffer.finish);
    end;

    begin {main}
            initialize_buffer;
            increment(buffer);
    end.
