Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
The Intel sign-in experience has changed to support enhanced security controls. If you sign in, click here for more information.
27648 Discussions

Regression with "backspace" in 2023.0


The following program demonstrates an I/O regression with the backspace statement in 2023.0.

program test_backspace
  integer :: test_unit=4
  character(len=16) :: filename = 'test_file'
  integer :: status
  integer :: one = 1, two = 2, three = 3

  open(unit=test_unit, file=filename, form='unformatted',action='write')
  write(test_unit) one, two
  open(unit=test_unit, file=filename, form='unformatted',action='read')
  read(test_unit, iostat=status) one, two, three
  if( status == 0 ) then
     write(*,*) ' Read one more item than written????'
     read(test_unit, iostat=status) one, two
     if( status == 0 ) then
        write(*,*) ' Successfully read two items written:',one,two
        write(*,*) ' Failed to read after backspace, code=',status
     end if
  end if
end program test_backspace

$module load compiler compiler/2022.2.1

ifort -o test.ifort-2021.7 test-backspace.f90
$ ./test.ifort-2021.7
 Successfully read two items written:           1           2
$ module switch compiler compiler/2023.0.0

$ ifort --version
ifort (IFORT) 2021.8.0 20221119
Copyright (C) 1985-2022 Intel Corporation.  All rights reserved.
$ ifort -o test.ifort-2021.8 test-backspace.f90
$ ./test.ifort-2021.8
 Failed to read after backspace, code=          -1

ifx behaves in an identical manner.



0 Kudos
1 Solution
Black Belt Retired Employee

I've been involved in a discussion of this before. EOR applies only for a non-advancing READ. In an advancing READ, which this, is, trying to read past the end of the record is an error, not an EOR condition.  The standard says, "If an error condition occurs during execution of an input/output statement, the position of the file becomes indeterminate." Therefore, you can't reliably BACKSPACE to recover from this. Note that EOR is not an error.

That INQUIRE changes the behavior is unfortunate, but the example program here is relying on undefined behavior. The only way to recover from this is to REWIND the file and then start reading again.

View solution in original post

26 Replies
Honored Contributor II

FYI That ran fine in Fortran Compiler Classic 2021.7.0 [Intel(R) 64] under debug.



Black Belt Retired Employee

@ATr , please do not add an unrelated issue to an existing thread - your question has nothing to do with BACKSPACE. Start a new thread.

I will note that 1) You do not say how it doesn't work, 2) The compiler you installed is 2-3 years old.  The code you have just goes into an infinite loop rereading the string for me.


Just to clarify all that

1. I am using VS 2019 under Win 10 and till now was using OneAPI 2022.3 and same version of the HPC toolkit;

only 64 bit compiler was used   IFORT only (classic compiler)

2. By some stupid action in VS 2019 (it was saying that some Intel extensions slow down the editing and maybe it would be helpful to

remove them... and I made this stupid step) I lost the Intel Fortran integration (repair did not help)

3. So I decided to switch to the new OneAPI 2023 (I installed it from Intel web site two days ago) and corresponding version of the HPC toolkit; this helped me to recover  Intel Fortran integration with the VS 2019

4. So I started to build my Fortran project in the debug mode but I noticed that  the  read statement in one of my functions  does not work as before; when you run the project a break point is announced and application stops; this happens when you run it with or without debugger; when I make a release version then I do not observe this problem


5. in this minimal example there is obviously an infinite loop but please note that by adding iostat to the read statement the current status (err_flag variable) will change its initial value (which was set to 0)  when the error is detected and the loop will be stoped;

this what I see under debugger is that err_flag is  -1 when the error is detected but then there is a break point and there is end of the story no way to continue program execution;


6. changing format from '(A)' to * does not help; this what helps is adding    end=100 to the read statement

and then just adding label 100


unfortunately I am using read(..) with iostat option also in other contexts ( for instance to retrieve different data values (floats, ints, strings) just from the line of standard text


7. As I do not have much time and cannot wait I came back the the 2022.3 version and this one works fine;


in the first iteration everything is read properly so  err_flag is still 0 ; in the second iteration err_flag = -1 and the loop is stopped;

in 2023 Intel compiler in the debug mode applications stops and a break point is generated

since 2012 till 2022 this was working as expected (at least for me) without any problem but in 2023 it does not (at least in the debug mode)

err_flag = 0
do while (err_flag.eq.0)
read(191,*,iostat=err_flag) line
end do


8.  I am sorry that I added this problem to this thread but I had a feeling that problem I have discovered is very close to this one;


9. and.. here is the command line

/nologo /debug:full /MP /Od /assume:buffered_io/DNO_LAGR_MULT_APPROACH  /DNO__NSCNT_NAGATA /u /assume:nocc_omp /standard-semantics /warn:uncalled /Qauto /align:dcommons /align:sequence /assume:byterecl /Qinit:zero /fp:precise /Qfp-speculation=off /names:uppercase /iface:cvf /module:"..\..\..\Obj\Release-x64\z_calc\\" /object:"..\..\..\Obj\Release-x64\z_calc\\" /Fd"..\..\..\Obj\Release-x64\z_calc\\vc160.pdb" /traceback /check:pointer /check:bounds /check:uninit /check:stack /libs:dll /threads /dbglibs /c







New Contributor II

@ATr  FYI your code also runs OK on Windows using ifort (IFORT) 2021.8.0 Debug x64 .

Which compiler did you use previously? Was it 2-3 years old?

Best to create a new thread as this was originally about BACKSPACE although INQUIRE seemed to emerge as the problem statement. This thread has been supposedly resolved (Green Tick) so most users will miss new posts from now on.

New Contributor II


A couple of things to try that I have resorted to in the past.

Did you clean the solution before recompiling in with the latest compiler?

Another tip is to try renaming/deleting the vs .suo file (in .vs folder of the solution folder) so that a new one is generated.  




whenever I make a release or a debug build  I do always make clean solution fisrt and then rebuild everything

vs  subdir was deleted (it had to be deleted if I remember well)

but anyway thanks for the hints

I will install again latest oneAPI and VS 2019 but on my older laptop with win10 and will try to reproduce the problem

if it still exists I will create a new thread

thank you all