Silverfrost Forums

Welcome to our forums

Compiler does not flag error in assignment statement

4 Jan 2023 1:08 #29730

In the following program, the first executable statement is in error because the right hand side expression is array valued, and the variable on the left is scalar.

Compiler versions 8.90 and 8.92 do not detect the error at compile time or, with /check, at run time.

program xm
   implicit none
   integer :: ix(5) = [5, 4, 8, 2, 7], ir
!
   ir = minloc(ix)      ! Error: return value is array, IR is scalar
   print *,ir
   print *,minloc(ix)
end program
5 Jan 2023 7:05 #29735

mecej4

At the moment an error report is only generated when /ISO is applied.

The logic behind this choice is not obvious to me. There should at least be a warning if not an error report. I will log it as needing investigation.

This issue is discussed here... https://forums.silverfrost.com/Forum/Topic/1755&start=0&postdays=0&postorder=asc&highlight=minloc.

5 Jan 2023 8:01 #29738

For the next release of FTN95 this code will generate an error report when /ISO is used and will otherwise generate a warning message.

5 Jan 2023 3:38 #29754

How this demo example should be written to be correct? Intuitively it looks OK.

5 Jan 2023 4:30 #29755
program xm
   implicit none
   integer :: ix(5) = [5, 4, 8, 2, 7], ir(1)
   ir = minloc(ix)
   print *,ir
   print *,minloc(ix)
end program
6 Jan 2023 4:10 #29761

Then in this specific case it is reasonable that FTN95 not following the crowd and not strictly supporting Standard. It is very natural for the compiler to adopt such a jargon, slang or idiomatic expression and excuse the human for not declaring ir as an array and declare it as usual scalar variable. It's counterintuitive to declare variable as an array with just 1 element for minloc to work. To me the warning indeed could be enough here.

I remember similar case caused me brain damage 20 years ago when i tried to use minloc and maxloc 😃

Please login to reply.