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

{$d+}
program d04a( output );
const
   testTemp = 30;
type
   temperature = -10..40;
var
   f  : array[0..1] of file of temperature;
   pr : packed record
           t1, t2 : temperature;
        end;
   k  : integer;

function side : integer;
begin
   side := k;
   k := k+1;
end;
begin {d04a}
   rewrite( f[0] );
   k := 0;
   write( f[side], testTemp, testTemp+1 );
   if k <> 1 then
      writeln( 'write binary for debug has side effects' );
   reset( f[0] );

   k := 0;
   read( f[side], pr.t1, pr.t2 );
   if k <> 1 then
      writeln( 'read binary for debug has side effects' )
   else if (pr.t1 <> testTemp) or (pr.t2 <> testTemp+1) then
      writeln( 'expected (', testTemp:1, ' ', testtemp+1:1, '), found (',
                pr.t1:1, ', ', pr.t2, ')' );

   read( f[0], pr.t1 ); { end of file! no data ==> file error }
   writeln( 'fails: read packed binary file error not detected' );
end. { d04a }

