Following program: program bsccbroken write(*,*) '\"ABCDEF\"' write(*,*) '\"ABCDEF\"\0' write(*,*) '\"#\"' write(*,*) '\"#\"\0' end program bsccbroken
When compiled with ifort version 15.0.2:
ifort -assume bscc -warn all -g -o bscc bscc.f
Produces following output:
[bma@localhost f]$ ./bscc
Please notice that closing quote is not included when \0 is appended to the end of the string. I work with large legacy code base where those closing zero bytes (\0) are very often included to ensure interoperability with C APIs.
While using IBM fortran xlf90 produces expected result:
$ xlf90 -o bscc bscc.f
** bsccbroken === End of Compilation 1 ===
1501-510 Compilation successful for file bscc.f.
Is it well known problem with -assume bscc option? Is there a patch for this? Is this behavior different in newer versions of Composer Studio?
Thanks in advance for any information.
The problem here is that Intel Fortran doesn't recognize \" as a valid escape sequence (reference). The manual says:
If a string contains an escape sequence that isn't in this table, the backslash is ignored.
I admit it is a bit weird that it throws away the \0 in this case - that may be a bug in itself. If you don't have any unrecognized sequences, then \0 is processed properly.
I was able to reproduce this behavior in 19.0.5.