I finally decided to ALLOCATE some time for getting less uncomfortable with the use of POINTERs - specifically to implement a simple linked list facility for CHARACTER data, using code in Metcalf & Reid as a starting point.
The following code contains what seem to me to be two entirely equivalent assignments. FTN95 is quite happy with code that uses the line commented out with 😃. However, using instead the two lines commented out with 😦, the CHECKMATE build gives the runtime error message 'Reference through unset FORTRAN pointer', and DEBUG and RELEASE builds report access violation.
I know the use of POINTER is fraught with subtle traps for the uninitiated - that's why I've avoided using them for as long as I have - so I'm not confident my code doesn't contain one such, but it looks like a compiler bug to me :? . If it's my error, could someone please explain the distinction between the two ways of doing the assignment?
Andy
program stack_tester
use subs
use stack_tracker
call create_stack
call a
stop
end program stack_tester
module subs
use stack_tracker
contains
!------------- subroutine a call push_name ('a') call pop_name return end subroutine a !------------- end module subs
module stack_tracker
integer, parameter :: worlen = 16
type stack_id
character (len = worlen) has_control
type (stack_id), pointer :: had_control
end type stack_id
type (stack_id), pointer :: stack_head, stack_item
contains
!------------- subroutine create_stack allocate (stack_head) stack_head% has_control = 'Main' nullify (stack_head% had_control) return end subroutine create_stack !------------- subroutine push_name (routine_name) character (len = *) routine_name allocate (stack_item) !:-) stack_item = stack_id (routine_name, stack_head) !:-( stack_item% has_control = routine_name !:-( stack_item% had_control = stack_head stack_head ⇒ stack_item return end subroutine push_name !------------- subroutine pop_name stack_item ⇒ stack_head stack_head ⇒ stack_head% had_control deallocate (stack_item) return end subroutine pop_name !------------- end module stack_tracker