replica nfl jerseysreplica nfl jerseyssoccer jerseyreplica nfl jerseys forums.silverfrost.com :: View topic - Puzzle
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 

Puzzle

 
Post new topic   Reply to topic    forums.silverfrost.com Forum Index -> General
View previous topic :: View next topic  
Author Message
Kenneth_Smith



Joined: 18 May 2012
Posts: 801
Location: Hamilton, Lanarkshire, Scotland.

PostPosted: Thu Oct 10, 2024 12:11 pm    Post subject: Puzzle Reply with quote

This is not a bug report, since I cannot determine what a standard conforming compiler should actually do with this code. So it's a puzzle for those that like that kind of thing.

Code:
module kind_mod
implicit none
integer, parameter :: dp = kind(1.d0)
end module kind_mod


module x_mod
use kind_mod
implicit none
real(dp) :: a = 1.d0
end module x_mod


module y_mod
use x_mod
implicit none
private           
public b          ! Only b is public, not clear to me if a from x_mod or dp from kind_mod
                  ! should be visible from the main program that uses y_mod
real(dp) :: b = 2.d0
end module y_mod


program main
use y_mod
print*, a         ! FTN95 prints the correct value, is this correct?
print*, b
print*, dp        ! FTN95 prints the correct value, is this correct?
end program main

! AI analysis
! Visibility of a:
! a is defined in x_mod and x_mod is used in y_mod. However, because y_mod declares private,
! everything in x_mod (including a) should be private unless explicitly made public in y_mod.
! Since a is not listed as public, it is not visible in main.
! Attempting to print a should cause a compilation error.
!
! Visibility of b:
! b is explicitly made public in y_mod, so it is visible in main and should print the value
! of 2.0.
!
! Visibility of dp:
! dp is defined in kind_mod and is used by x_mod. x_mod is used by y_mod. While dp is
! publicly accessible in kind_mod, it is not made private anywhere. Since y_mod does not
! explicitly hide it, dp should be visible in main and should print the kind value for
! double precision, which is typically 8.
!
! If the compiler adheres strictly to the Fortran standard: Attempting to access a would
! result in a compilation error, and the program would not compile due to a being private.
!
Back to top
View user's profile Send private message
PaulLaidler
Site Admin


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

PostPosted: Thu Oct 10, 2024 2:21 pm    Post subject: Reply with quote

Ken

If "implicit none" is added to the main program, FTN95 ought to fault the use of the variables a and dp.

It fails in this respect and I will note this as a bug that needs fixing.
Back to top
View user's profile Send private message AIM Address
Kenneth_Smith



Joined: 18 May 2012
Posts: 801
Location: Hamilton, Lanarkshire, Scotland.

PostPosted: Thu Oct 10, 2024 8:00 pm    Post subject: Reply with quote

Paul, Thanks for clearing this up. It was the failure of "IMPLICIT NONE" which caused the problem in the larger program I was looking at. The AI critique of simple example simply added to my confusion.
Back to top
View user's profile Send private message
mecej4



Joined: 31 Oct 2006
Posts: 1899

PostPosted: Fri Oct 11, 2024 12:02 am    Post subject: Reply with quote

Thanks, Kenneth, for this nice puzzling program. With these lines for the main program:
Code:
program main
use x_mod, only : a
use y_mod
use kind_mod
implicit none
print*, a         ! FTN95 prints the correct value, is this correct?
print*, b
print*, dp        ! FTN95 prints the correct value, is this correct?
end program main

The modified code works on Windows 11 with the current Intel IFX compiler, NAG 7219 and GFortran 11.4.
Back to top
View user's profile Send private message
Kenneth_Smith



Joined: 18 May 2012
Posts: 801
Location: Hamilton, Lanarkshire, Scotland.

PostPosted: Sat Oct 12, 2024 5:21 pm    Post subject: Reply with quote

mecej4, thanks for taking the time to look at this.
Back to top
View user's profile Send private message
PaulLaidler
Site Admin


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

PostPosted: Fri Jan 31, 2025 8:07 am    Post subject: Reply with quote

This bug has now been fixed for the next release of FTN95.
Back to top
View user's profile Send private message AIM Address
Display posts from previous:   
Post new topic   Reply to topic    forums.silverfrost.com Forum Index -> General 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