View previous topic :: View next topic |
Author |
Message |
mecej4
Joined: 31 Oct 2006 Posts: 1896
|
Posted: Wed Jan 04, 2023 2:08 pm Post subject: Compiler does not flag error in assignment statement |
|
|
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.
Code: | 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 |
|
|
Back to top |
|
|
PaulLaidler Site Admin
Joined: 21 Feb 2005 Posts: 8012 Location: Salford, UK
|
|
Back to top |
|
|
PaulLaidler Site Admin
Joined: 21 Feb 2005 Posts: 8012 Location: Salford, UK
|
Posted: Thu Jan 05, 2023 9:01 am Post subject: |
|
|
For the next release of FTN95 this code will generate an error report when /ISO is used and will otherwise generate a warning message. |
|
Back to top |
|
|
DanRRight
Joined: 10 Mar 2008 Posts: 2864 Location: South Pole, Antarctica
|
Posted: Thu Jan 05, 2023 4:38 pm Post subject: |
|
|
How this demo example should be written to be correct?
Intuitively it looks OK. |
|
Back to top |
|
|
PaulLaidler Site Admin
Joined: 21 Feb 2005 Posts: 8012 Location: Salford, UK
|
Posted: Thu Jan 05, 2023 5:30 pm Post subject: |
|
|
Code: | program xm
implicit none
integer :: ix(5) = [5, 4, 8, 2, 7], ir(1)
ir = minloc(ix)
print *,ir
print *,minloc(ix)
end program |
|
|
Back to top |
|
|
DanRRight
Joined: 10 Mar 2008 Posts: 2864 Location: South Pole, Antarctica
|
Posted: Fri Jan 06, 2023 5:10 am Post subject: |
|
|
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 |
|
Back to top |
|
|
|