0

I'm working with some legacy Fortran code and discovered some warnings using compile-time caller-callee mismatch detection (ifort's -gen-interfaces -warn interfaces). I received some warning in the following situations:

  1. The caller passes a variable real*8 x (i.e. scalar) to a subroutine, while the subroutine expects a real*8 x(1) (i.e. an array)
  2. The opposite from case 1: The caller passes a real*8 x(1) to a subroutine, while the subroutine declares x as real*8 x

Now, is that acceptable? As far as I can see there is no problem with that, I'm I right? Or could there arise any problems?

Raphael Roth
  • 26,751
  • 15
  • 88
  • 145
  • 1
    There's probably a difference between ["allowed by Fortran standard"](https://stackoverflow.com/q/7805467), and "will work". Things that aren't allowed may indeed give rise to unexpected problems. – francescalus Jan 25 '17 at 09:53
  • This sounds very similar to http://stackoverflow.com/questions/41630361/passing-scalars-and-array-elements-to-a-procedure-expecting-an-array We should know whether there is explicit interface available for your subroutine. – Vladimir F Героям слава Jan 25 '17 at 11:31
  • It formerly worked, or can work in some cases where functions/subroutines are linked after compiling. These days (post F90) you are probably better off with MODULE/PROCEDURE to accept either and perform the operation the same both ways. The compilers are basically better so there is more checking that the arguments are correct... Which is also where typically a lot of the problems happen (almost always at the interfaces)! – Holmz Jan 25 '17 at 11:55

1 Answers1

0

Failure would occur if the target abi isn't compatible with this standard violation. For the case where the callee array could be declared intent(in), it can be fixed by promoting the caller argument with constructor e.g. [x]

tim18
  • 580
  • 1
  • 4
  • 8