Most file variables have an associated buffer variable, which provides direct access to the next value waiting to be read from the file, or the next value to be written to the file.
In Standard Pascal (i.e. ISO/IEC 7185), file variables can be opened in one of two modes:
When a file variable is opened in write-only mode, the contents of the buffer variable associated with the file variable is initially undefined. You can write values to the file associated with the file variable, by assigning values to the buffer variable associated with the file variable, and using the built-in procedure put to write the contents of the buffer variable to the file.
Irie Pascal allows file variables to be opened in read/write mode, where values can be both read from, and written to the files associated with the file variables. If you reference the buffer variable of a file variable opened in read/write mode, it is unclear whether you intend to read from the file (in which case the next available value from the file should be transferred to the buffer variable), or whether you intend to write to the file (in which case no I/O should take place). Because of this uncertainty it is not recommended that you use buffer variables and the low-level I/O procedures, get and put, on file variable opened in read/write mode. Instead it is recommended that you use the high-level I/O procedures read, write, etc to read and write from file variables opened in read/write mode.
Buffer variables are created and destroyed when their associated file variables are created and destroyed.
The simple example program below uses a file variable (f) to create a file called numbers.dat and uses the associated buffer variable (f) to write the numbers 1 to 10 to the file.
program numbers; var f : file of integer; i : integer; begin assign(f, 'numbers.dat'); rewrite(f); for i := 1 to 10 do begin f^ := i; put(f) end end.
The syntax for referencing buffer variables is given below:
(NOTE: for clarity some parts of the syntax are omitted, see Irie Pascal Grammar for the full syntax):
buffer-variable = file-variable '^' | file-variable '@'
Where file-variable is a reference to a file variable.