forums.silverfrost.com Forum Index forums.silverfrost.com
Welcome to the Silverfrost forums
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Subroutine inside an interface inside another subroutine...

 
Post new topic   Reply to topic    forums.silverfrost.com Forum Index -> 64-bit
View previous topic :: View next topic  
Author Message
StamK



Joined: 12 Oct 2016
Posts: 159

PostPosted: Tue Jun 25, 2019 10:06 pm    Post subject: Subroutine inside an interface inside another subroutine... Reply with quote

The following code works fine in 32bit but not in 64bit:

Code:

!ftn95$free

module test

contains
SUBROUTINE TESTOUTER(IWIN, IEVENT, C80)
  CHARACTER*(*)   :: C80


  interface
    subroutine TESTINNER(iwin, ievent, c80)
      character*(*)         :: c80
   end subroutine
  end interface
      
  SAVE

  CALL TESTINNER(iwin, ievent, c80)

END SUBROUTINE

subroutine TESTINNER(iwin, ievent, c80)
      character*(*)         :: c80
      PRINT*,iwin, ievent, c80
End subroutine

end module test

program main
   use test
   character*20   :: c80
 
   c80 = "test"
   
  IWIN=1
  IEVENT = 10
  call TESTOUTER (IWIN, IEVENT, C80)
end program


In 32bit it works fine, but in 64bit:

[SLINK64 v2.10, Copyright (c) Silverfrost Ltd. 2015-2018]
Loading C:\wlib64s\test-interface2\main.obj
Creating executable file main.exe
The following symbols were not defined:

TESTINNER
Back to top
View user's profile Send private message
PaulLaidler
Site Admin


Joined: 21 Feb 2005
Posts: 7912
Location: Salford, UK

PostPosted: Wed Jun 26, 2019 8:55 am    Post subject: Reply with quote

TESTINNER is implicitly EXTERNAL and does not need an INTERFACE.

The code does not compile with gFortran and, off hand, I don't know how an interface ought to be presented in this context.

For FTN95 the behaviour does differ between 32 and 64 bits and at the moment I don't know why. If you want to retain the interface then FTN95 allows you to present it in the header part (before the CONTAINS), and this works for both 32 and 64 bits. However, it is quite possible that this information is ignored.

The MAP file for linking gives a clue. For some reason TESTINNER has got "mangled" as though it were internal.

In short, I think there is something here that we need to look at but at the same time I suspect that the code may not be right.
Back to top
View user's profile Send private message AIM Address
DietmarSiepmann



Joined: 03 Jun 2013
Posts: 279

PostPosted: Wed Jun 26, 2019 9:31 am    Post subject: Reply with quote

Paul, StamK,

to your information: the code also does not build with INTEL's ifort compiler and produces an analogous error message (i.e. unresolved external symbol TESTINNER ...).

Regards,
Dietmar
Back to top
View user's profile Send private message
mecej4



Joined: 31 Oct 2006
Posts: 1884

PostPosted: Wed Jun 26, 2019 11:38 am    Post subject: Reply with quote

The Fortran standard says (F2008, 12.4.3.1, Note 12.2; similarly in F95, 12.3.2, Note 12.3)

Quote:
NOTE 12.2
An interface body cannot be used to describe the interface of an internal procedure, a module procedure that is not a separate module procedure, or an intrinsic procedure because the interfaces of such procedures are already explicit. However, the name of a procedure may appear in a PROCEDURE statement in an interface block (12.4.3.2).


Therefore, the presence of the interface block in the example code makes the code non-conforming.

The Fortran standard does not (with a few exceptions) specify what a compiler should do with non-conforming code. Ideally, a compiler should flag an attempt to provide an interface block for an internal procedure. However, after seeing the interface block, which appears prior to the declaration of the conflicting internal procedure, the compiler may decide to take the presence of the interface block as a hint to treat it as an interface to an external procedure. Luckily for us, there is no such external procedure, so we get a linker error (unsatisfied external). If this were not so, we would have had a more perplexing debugging problem at run time.

Regardless of what the compiler does with non-conforming code, users will be surprised when the 32- and 64-bit compilations produce entirely different error messages. I am inclined to think that it a more serious compiler bug when, given faulty source code, the compiler not only produces an EXE but the resulting program "works fine" in the eye of the user.
Back to top
View user's profile Send private message
StamK



Joined: 12 Oct 2016
Posts: 159

PostPosted: Wed Jun 26, 2019 12:05 pm    Post subject: Reply with quote

Thanks for that. I have now moved it into the main interface block in the module (before contains) and it works fine.
Back to top
View user's profile Send private message
PaulLaidler
Site Admin


Joined: 21 Feb 2005
Posts: 7912
Location: Salford, UK

PostPosted: Wed Jun 26, 2019 12:31 pm    Post subject: Reply with quote

My comment above was based on a misunderstanding. I thought that the interface was for an external routine whereas it is in fact internal to the module.

So such an interface is never needed and for some compilers is not permitted.

My recommendation is to leave it out.
Back to top
View user's profile Send private message AIM Address
LitusSaxonicum



Joined: 23 Aug 2005
Posts: 2388
Location: Yateley, Hants, UK

PostPosted: Thu Jun 27, 2019 10:58 am    Post subject: Reply with quote

Sometimes you just have to accept that a part of Fortran is a riddle wrapped in a mystery inside an enigma. Fortran is mainly a catalogue of blunders.

Eddie (channelling WSC)
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    forums.silverfrost.com Forum Index -> 64-bit All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
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