ifort command-line vs Visual Studio (assumed shape array)

83 views Asked by At

Recently I encountered the following issue:

I made this very simple program in Visual Studio Enterprise 2022, Intel® Fortran Compiler Classic 2021.10.0, Windows 10:

program test
    implicit none
    integer, dimension(3):: x=[1, 2, 3]
    integer, external:: f
    integer:: y

    y = f(x)
end program test

integer function f(x) result(r)
    implicit none
    integer, dimension(:), intent(in):: x
    
    print*, x(2)
    r=2
end function f

To my surprise, it compiled and ran perfectly. I say to my surprise because to my understanding, this is not standard Fortran. And sure enough when I tried to compile it with gfortran it does throw an error telling me to use an interface. To make things worse, when I tried to compile it with command line ifort it did compile it but the executable wouldn't ran, with a "Program Exception - access violation" error.

Sidenote: If I replace the function with a subroutine then gfortran and ifort IDE throw the same error ("use an interface") but ifort in command-line still compiles it fine but can't run the executable.

So here are my questions:

  1. Why all those difference behaviours (I know gfortran is the correct/standrad one)? I would at least expect the two iforts (IDE and cmd) to have the same effects.
  2. How can I force Visual studio to run ifort in the standard protocol (I tried adding the /stand switch but it didn't work)?
  3. How can I make command-line ifort to run this code (since evidently, with the proper flags it can run it)

Here are the switches that the Visual Studio uses, which none of them should contribute to this behaviour I think:

enter image description here

0

There are 0 answers