{: test that reading a variable from a file causes a fatal error if
   there is a file error}

{$d+}
program d049( output );

const
   testInt = 783;
var
   f : file of integer;
   k : integer;
   a : array[0..10] of integer;

function side : integer;
begin
   side := k;
   k := k+1;
end;
begin {d049}
   rewrite( f );
   write( f, testInt );
   reset( f );

   k := 0;
   read( f, a[side] );
   if k <> 1 then
      writeln( 'read char for debug has side effects' )
   else if a[0] <> testInt then
      writeln( 'expected ', testInt:1, ' found ', a[0] );

   read( f, a[1] ); { end of file! no data ==> file error }
   writeln( 'fails: read integer file error not detected' );
end. { d049 }

