Recently, I started using the gfortan-10.2-BigSur-Intel compiler and observed ambiguous behavior when a function defined in a module is to write a string to standard output. Concretely, I have a module function "PrintToScreen" that prints a given character string "str" to standard output, while returning an integer error code. Then, I ask to write the error code in the calling program, using the code
INTEGER (KIND = 4) :: ios
...
ios = PrintToScreen(str);
PRINT '(t1, a, i4)', 'ios = ', ios
...
As a result, "str" is displayed on screen by "PrintToScreen", followed by ios, as expected. However, if I avoid the detour via "ios" by using the simpler code
...
PRINT '(t1, a, i4)', 'ios = ', PrintToScreen(txt)
...
the program stalls as soon as the function "PrintToScreen" is entered, while also "str" is left unprinted. Also, if I make "PrintToScreen" write "str" to a text file instead of standard output, the two pieces of code yield the same result. Finally, I checked the code on a Linux machine (Debian Buster) and no problems occurred.
How do I fix this?