BACKSPACE statement

Standard: F77 F90 F95 F2003 F2008 F2018 Example program


BACKSPACE (bs-spec-list)
BACKSPACE expression

bs-spec-list ::= bs-spec [,bs-spec]...

bs-spec ::= [ UNIT= ] expression
| ERR=label
| IOMSG=variable
| IOSTAT=variable

The UNIT= specifier is required, and the optional UNIT= can be omitted only if it is the first bs-spec. The expression for the UNIT= specifier must be a scalar integer expression whose value identifies a valid i/o unit. The variable for the IOSTAT= specifier must be a scalar integer variable, and should not be smaller than 16 bits. The variable for the IOMSG= specifier must be a scalar default character variable.

The “BACKSPACE expression” form is equivalent to “BACKSPACE (UNIT=expression)”.


Backspaces an input/output unit one record.

Note that some files are incapable of being backspaced (an error will occur).

The IOMSG= specifier was added in Fortran 2003; if an error occurs, this sets a character string variable to an error message, otherwise it is unchanged. The ERR= or IOSTAT= specifier is still needed to prevent termination on error.


CLOSE statement, ENDFILE statement, ERR= specifier, IOMSG= specifier, IOSTAT= specifier, OPEN statement, PRINT statement, READ statement, REWIND statement, UNIT= specifier, WRITE statement