Re: backspace error (reading file from the end)



Richard Maine wrote:
....
The fact that some implementations disallow backspace on some files
(and yes, the standard allows an implementation to place such
limitations) is one reason why I recommend avoiding the use of
backspace. It is annoying when you find that your program doesn't work
when it takes input from a pipe instead of a disk file, for example.

Programmers should always be aware of what "files" are
(or might be) pipes and what files really are exernal storage.
Direct access I/O also doesn't work well with pipes. The
issue is similar.

I tend to use BACKSPACE very sparingly. The usual pattern
is that I have program that produces files whose length and
structure is unknown a-priori. I have to output things on the
fly, so to speak. So, I create a data structure that describes
what's on the file and write that out last. But, I then have to
read that "directory" structure by positioning the file at the
end and reading backwards (well, backspacing a few times
and reading forwards). Since I don't need to do this often,
BACKSPACE is rarely needed.

Sure, I could write that "directory" on a separate file and
(hope that I) keep them both together. That's a poor second
choice. A really poor third choice is to have to rewrite the
file with the "directory" at the beginning.

BACKSPACE should work portably on sequential formatted
files (not pipes) and on sequential non-stream unformatted
files (again non pipes). The "quality of implementation" of
any Fortran environment that failed to do these efficiently
would be unacceptable.

--
J. Giles

"I conclude that there are two ways of constructing a software
design: One way is to make it so simple that there are obviously
no deficiencies and the other way is to make it so complicated
that there are no obvious deficiencies." -- C. A. R. Hoare


.