lfortran / lfortran

Official main repository for LFortran
https://lfortran.org/
Other
942 stars 152 forks source link

Stdlib: Bug in unformatted read() #3679

Open Shaikh-Ubaid opened 6 months ago

Shaikh-Ubaid commented 6 months ago
% cat examples/expr6.f90     
program expr2
    implicit none
    integer :: x

    open(1, form="unformatted", file="tmp.txt")
    read(1) x
    close(1)

    print *, x
end program
% gfortran examples/expr6.f90
% ./a.out 
         125
% lfortran_in_main examples/expr6.f90 
4
Shaikh-Ubaid commented 6 months ago

The tmp.txt file was generated using

program expr2
    implicit none
    open(1, form="unformatted", file="tmp.txt")
    write(1) 125
    close(1)
end program
Pranavchiku commented 6 months ago

Because of Stdlib:, I am assuming this is related to stdlib

certik commented 6 months ago

We should not read GFortran's files. The "unformatted" is compiler specific. I recommend to just save/load using the regular binary IO that we already support.