View Issue Details

IDProjectCategoryView StatusLast Update
0038476FPCCompilerpublic2021-02-22 18:49
ReporterJuan Díaz Assigned ToFlorian  
PrioritynormalSeverityminorReproducibilityhave not tried
Status resolvedResolutionno change required 
PlatformWindows, 32 bitsOSWindows 
Product Version3.2.0 
Fixed in Version3.3.1 
Summary0038476: In ISO mode external binary files are not created
DescriptionA program compiled in ISO mode where a binary file is listed in the program heading does not create that file.
For instance, if the following program:

program TestExternalBinaryFiles(foi); { <--- file foi is listed as a file parameter in the program statement }

var i: integer;
       foi: file of integer;

begin
    rewrite(foi);
    for i := 1 to 1000 do write(foi, i)
end .

is compiled like this: fpc -Miso TestExternalBinaryFiles.pas
and then it is run on the command line entering the name of the file to be created: TestExternalBinaryFiles foi
the program does not create the external file foi.

After compiling the following program, which is the same as the one above except for the lines that have been added for echo printing the contents of the file foi to the standard textfile output:

program TestExternalBinaryFiles(foi, output); { <--- file foi is a parameter of the program }

var i: integer;
       foi: file of integer;

begin
    {create file foi}
    rewrite(foi);
    for i := 1 to 1000 do write(foi, i);
    {echo print file foi}
    reset(foi);
    while not eof(foi) do
        begin read(foi, i); write(i)
        end
end .

fpc -Miso TestExternalBinaryFiles.pas
and typing in at the command line: TestExternalBinaryFiles foi
the program only writes the contents of the file foi to the console and no external file foi is created, which is disappointing. This tells us that file foi is created but just as a scratch file and not as an external file.
So, the program behaves as if it had been written without listing file foi in the heading, as if the code had been:

program TestExternalBinaryFiles(output); { <-- file foi is not a parameter in the program heading }

var i: integer;
      foi: file of integer;

begin
    {create file foi}
    rewrite(foi);
    for i := 1 to 1000 do write(foi, i);
    {echo print file foi}
    reset(foi);
    while not eof(foi) do
        begin read(foi, i); write(i)
        end
end .

In this case file foi is a scratch file.


It is curious that when it comes to binary files, a program compiled in ISO mode does not create the files, but when listing textfiles in the program heading the program does create the files. For example:

program TestExternalTextFiles(tf);

var i: integer;
       tf: text;

begin
    rewrite(tf);
    for i := 1 to 1000 do write(tf, i)
end .

After compiling with: fpc -Miso TestExternalTextFiles.pas
and typing in at the command line: TestExternalTextFiles tf.txt
an external file tf.txt is indeed created.

I wiould appreciate it if this issue were addressed. Thanks in advance.
Steps To ReproduceCreate file TestExternalBinaryFiles.pas and type in the following piece of code :

program TestExternalBinaryFiles(foi, output); { <--- file foi is a parameter of the program }

var i: integer;
       foi: file of integer;

begin
    {create file foi}
    rewrite(foi);
    for i := 1 to 1000 do write(foi, i);
    {echo print file foi}
    reset(foi);
    while not eof(foi) do
        begin read(foi, i); write(i)
        end
end .

Then compile at the command line in ISO mode: fpc -Miso TestExternalBinaryFiles.pas

Run the program at the command line. On Windows, run the program like this: TestExternalBinaryFiles foi
TagsNo tags attached.
Fixed in Revision
FPCOldBugId
FPCTarget-
Attached Files

Activities

Juan Díaz

2021-02-11 23:34

reporter  

TestExternalBinaryFiles.pas (305 bytes)   
program TestExternalBinaryFiles(foi, output);

var i: integer;
    foi: file of integer;

begin
   {create file foi}
   rewrite(foi);
   for i := 1 to 1000 do write(foi, i);
   {echo print file foi}
   reset(foi);
   while not eof(foi) do
      begin read(foi, i); write(i)
      end
end .
TestExternalBinaryFiles.pas (305 bytes)   

Florian

2021-02-21 22:43

administrator   ~0129072

This is already fixed in trunk.

Juan Díaz

2021-02-22 18:49

reporter   ~0129105

That is very good news. Thanks.

Issue History

Date Modified Username Field Change
2021-02-11 23:34 Juan Díaz New Issue
2021-02-11 23:34 Juan Díaz File Added: TestExternalBinaryFiles.pas
2021-02-21 22:43 Florian Assigned To => Florian
2021-02-21 22:43 Florian Status new => resolved
2021-02-21 22:43 Florian Resolution open => no change required
2021-02-21 22:43 Florian Fixed in Version => 3.3.1
2021-02-21 22:43 Florian FPCTarget => -
2021-02-21 22:43 Florian Note Added: 0129072
2021-02-22 18:49 Juan Díaz Note Added: 0129105