|
forums.silverfrost.com Welcome to the Silverfrost forums
|
View previous topic :: View next topic |
Author |
Message |
simon
Joined: 05 Jul 2006 Posts: 268
|
Posted: Wed May 27, 2020 3:24 pm Post subject: generic interface |
|
|
I reported the following code to NAG as a suspected error, since their compiler was complaining about the two subroutines s1 and s2 being indistinguishable.
Code: | Module m
Interface s
Module Procedure s1
Module Procedure s2
End Interface s
!
Contains
!
Subroutine s1 (i, c)
Integer, Intent(In) :: i
Character(Len=*), Intent(In) :: c
Return
End Subroutine s1
!
Subroutine s2 (c, i)
Character(Len=*), Intent(In) :: c
Integer, Intent(In) :: i
Return
End Subroutine s2
End Module m |
The code compiles without an error in FTN95. However, NAG indicated that the code is incorrect because
would be ambiguous since the ordering of the arguments does not matter even though the arguments are not optional. So perhaps FTN95 should issue a compilation error message? |
|
Back to top |
|
|
PaulLaidler Site Admin
Joined: 21 Feb 2005 Posts: 7924 Location: Salford, UK
|
Posted: Thu May 28, 2020 8:10 am Post subject: |
|
|
Thank you for the feedback. You are right. FTN95 does not fault this even when using /ISO. |
|
Back to top |
|
|
John-Silver
Joined: 30 Jul 2013 Posts: 1520 Location: Aerospace Valley
|
Posted: Mon Jun 08, 2020 12:04 pm Post subject: |
|
|
what would be the effect of this in this case ? ..... wrong answers ? .... or the appearance in some form of Dan Devilry ? _________________ ''Computers (HAL and MARVIN excepted) are incredibly rigid. They question nothing. Especially input data.Human beings are incredibly trusting of computers and don't check input data. Together cocking up even the simplest calculation ... " |
|
Back to top |
|
|
mecej4
Joined: 31 Oct 2006 Posts: 1886
|
Posted: Mon Jun 08, 2020 3:58 pm Post subject: |
|
|
Here is a fleshed out version of the test code. Since the ambiguity is not detected and the violation of the standard is not detected, the fact that the program runs is, in itself, the error. If the program output is seen to be reasonable, the bug can go undetected for years.
Code: | Module m
Interface s
Module Procedure s1
Module Procedure s2
End Interface s
!
Contains
!
Subroutine s1 (i, c)
Integer, Intent(In) :: i
Character(Len=*), Intent(In) :: c
print *,'S1: ',c,i
Return
End Subroutine s1
!
Subroutine s2 (c, i)
Character(Len=*), Intent(In) :: c
Integer, Intent(In) :: i
print *,'S2: ',c,i
Return
End Subroutine s2
End Module m
Program Smn
use m
character(len=5) :: cc = 'ABCDE'
integer :: i = 123
! when args are passed without keywords, the order/type suffices to select the specific routine
call s(i,cc)
call s(cc,i)
! when keywords are used, both s1 and s2 would match; if s1 is tried first, it will match
! and the bug is not found unless s2 is also tested even after s1 succeeded.
call s(c=cc, i=i)
call s(i=i, c=cc)
end Program |
|
|
Back to top |
|
|
PaulLaidler Site Admin
Joined: 21 Feb 2005 Posts: 7924 Location: Salford, UK
|
Posted: Sat Jul 04, 2020 8:47 am Post subject: |
|
|
This issue has now been fixed for the next release of FTN95. This kind of ambiguous interface will now be reported as an error. |
|
Back to top |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|