In ISO mode external binary files are not created
Original Reporter info from Mantis: juancdiaz
-
Reporter name: Juan Díaz
Original Reporter info from Mantis: juancdiaz
- Reporter name: Juan Díaz
Description:
A 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 reproduce:
Create 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
Mantis conversion info:
- Mantis ID: 38476
- OS: Windows
- OS Build: 7
- Platform: Windows, 32 bits
- Version: 3.2.0
- Fixed in version: 3.3.1