{

A "for" loop writes a byte from a function to each of the 4 bytes in an
array, but only the first byte of the array is changed.

Tested under DOS:
Free Pascal Compiler version 1.0.11 [2004/05/18] for i386
Copyright (c) 1993-2003 by Florian Klaempfl

I believe my logic is correct; the program ran as expected when compiled
with "TMT (R) Pascal Lite compiler. v.1.00 (Mar 23 1997)".

}


{ Attempts to write to all 4 bytes in an array; only the first byte
  is changed. }
program arraybug;
const
  buff_size = 4;
var
  buffer : array[ 1..buff_size ] of byte;
  { If ran_seed is changed to word, bug disappears!!! }
  ran_seed : dword;
  index : integer;

function random_byte: byte;
begin
  { If next line is commented out, the bug disappears!!! }
  ran_seed := ( ran_seed * 21 + 1 ) and $FF;
  { To demonstrate bug clearly, return 'E' instead of random byte. }
  random_byte := ord( 'E' )
end;

procedure smudge_array( var a : array of byte;  count : integer );
var i: integer;
begin
  write( 'Changing byte number ' );
  for i := 0 to pred(count) do
  begin
    write(i,' ');
    a[i] := random_byte
  end;
  writeln;
end;

procedure show_buffer;
var i : integer;
begin
  write( 'Buffer: ' );
  for i := 1 to buff_size do
    write( chr( buffer[i] ) );
  writeln;
end;

begin  
  for index := 1 to buff_size do
    buffer[index] := ord( '-' );
  show_buffer;
  ran_seed := 1984;
  smudge_array( buffer, buff_size );
  writeln( 'Buffer should now be "EEEE":' );
  show_buffer;
end.
