Legacy pgf90: print a fortran character(*) that has c-like delimiters;

Let us consider the following 1 line Fortran code:

program test
print*,’\n\n 12 \n3 \n \n5 6 \n 8’
end program test

I expected to see a single line (like in gfortran8+ or ifort)
however, pgf90 (18+)generate multiple lines output :


5 6
apparently as if it treats the ‘\n’ from within the fortran string as a c-like newline delimiter.

  1. Also the code:
    program test
    print*,’\\n\\n 12 \\n3 \\n \\n5 6 \\n 8’
    end program test

prints with pgf90:
\n\n 12 \n3 \n \n5 6 \n 8
instead of original fortran string
‘\\n\\n 12 \\n3 \\n \\n5 6 \\n 8’

is this compiler issue or fortran standard does not guarantee
print*’,\n\n 12 \n3 \n \n5 6 \n 8’
\n\n 12 \n3 \n \n5 6 \n 8

No sure what the Fortran standard says about blackslashes, but we do treat backslashes as escape characters by default. To treat them like any other character, add the “-Mbackslash” flag:

% nvfortran -help -Mbackslash
-M[no]backslash     Treat backslash like any other character in character strings
% nvfortran backs.f90 -Mbackslash
% a.out
 \n\n 12 \n3 \n \n5 6 \n 8

Hope this helps,