View Issue Details

IDProjectCategoryView StatusLast Update
0038506FPCRTLpublic2021-02-24 11:12
ReporterJuan Díaz Assigned To 
PrioritynormalSeverityminorReproducibilityalways
Status newResolutionopen 
Platformi386OSWindows 7 
Product Version3.2.0 
Summary0038506: Run-time error 100 is produced when an application applies the procedure GET to a binary file throughout
DescriptionWhen applying the procedure GET to files whose components are of file types other than text and end-of-file is reached,
run-time error 100 is reported. After compiling the following source code and executing the program, the run-time error in
question is produced.


{$mode iso}

program TestGetOnBinaryFiles(fr, output); {runtime error 100 is produced}

const max = 100;

type FileOfReal = file of real;

var fr: FileOfReal;

procedure createfileofreal(var fr: FileOfReal);
   var i: 1..max;
       r: real;
begin
   writeln;
   assign(fr, 'RealNumbers.dat');
   rewrite(fr);
   for i := 1 to max do
      begin
         r := i * 1.95;
         fr^ := r;
         put(fr)
      end ;
   close(fr)
end ;

procedure printfileofreal(var fr: FileOfReal);
begin
   writeln;
   writeln('Contents of file:');
   reset(fr);
   while not eof(fr) do
      begin
         writeln(fr^ :3:2);
         get(fr)
      end ;
   close(fr);
   writeln
end ;

begin
   createfileofreal(fr);
   printfileofreal(fr)
end .


However, when the file is of type text and the procedure GET is used to access all of its components, no run-time error occurs.

{$mode iso}

program TestGetOnTextfiles(f, output); {no run-time error is produced}

var f: text;
    ch: char;

begin
   writeln;
   writeln('Contents of file:');
   writeln;
   assign(f, 'ATextfile.txt');
   reset(f);
   while not eof(f) do
      begin
         ch := f^;
         write(ch);
         get(f)
      end ;
   close(f);
   writeln
end .


In my humble opinion, this issue should be fixed in order for FPC to comply with the ISO 7185 standard since the following example
from page 31 of the ISO 7185 Pascal standard document also causes the aforementioned run-time error.

procedure CopyFiles (var from, into : FileOfInteger);
begin
  reset(from) ; rewrite(into);
  while not eof(from) do begin
    into^ := from^;
    put(into) ; get(from)
  end
end { of CopyFiles };
Steps To ReproduceCompile the source code files attached and run the programs.
TagsISO 7185 Standard Pascal
Fixed in Revision
FPCOldBugId
FPCTarget
Attached Files

Activities

Juan Díaz

2021-02-18 04:44

reporter  

TestGetOnBinaryFiles.pas (748 bytes)   
{$mode iso}

program TestGetOnBinaryFiles(fr, output);

const max = 100;

type FileOfReal = file of real;

var fr: FileOfReal;

procedure createfileofreal(var fr: FileOfReal);
   var i: 1..max;
       r: real;
begin
   writeln;
   assign(fr, 'RealNumbers.dat');
   rewrite(fr);
   for i := 1 to max do
      begin
         r := i * 1.95;
         fr^ := r;
         put(fr)
      end ;
   close(fr)
end ;

procedure printfileofreal(var fr: FileOfReal);
begin
   writeln;
   writeln('Contents of file:');
   reset(fr);
   while not eof(fr) do 
      begin 
         writeln(fr^ :3:2); 
         get(fr)
      end ;
   close(fr);
   writeln
end ;

begin
   createfileofreal(fr);
   printfileofreal(fr)
end .
TestGetOnBinaryFiles.pas (748 bytes)   
TestGetOnTextfiles.pas (345 bytes)   
{$mode iso}

program TestGetOnTextfiles(f, output);

var f: text;
    ch: char;

begin
   writeln;
   writeln('Contents of file:');
   writeln;
   assign(f, 'ATextfile.txt');
   reset(f);
   while not eof(f) do
      begin
         ch := f^;
         write(ch);
         get(f)
      end ;
   close(f);
   writeln     
end .
TestGetOnTextfiles.pas (345 bytes)   
ATextfile.txt (68 bytes)   
First line.
Second line.
Third line.
Digits: 0 1 2 3 4 5 6 7 8 9.
ATextfile.txt (68 bytes)   

Bart Broersma

2021-02-24 11:12

reporter   ~0129140

Seems to run fine with fpc 3.3.1 r48092 on win32 and win64.

Issue History

Date Modified Username Field Change
2021-02-18 04:44 Juan Díaz New Issue
2021-02-18 04:44 Juan Díaz File Added: TestGetOnBinaryFiles.pas
2021-02-18 04:44 Juan Díaz File Added: TestGetOnTextfiles.pas
2021-02-18 04:44 Juan Díaz File Added: ATextfile.txt
2021-02-22 18:57 Juan Díaz Tag Attached: ISO 7185 Standard Pascal
2021-02-24 11:12 Bart Broersma Note Added: 0129140