I have a module that I am using to share variables across a program, and I have several modules that need to access that variable. I have one integer variable that is acting unexpectedly. I have a large subroutine that itself is not a module I'll call it subroutineA. subroutineA uses the shared variables module and the variable in question, but does not set it. subroutineA calls subroutineB that sets the variable in question to a value - in my case, 1761. subroutineB returns to subroutineA and all is well with the variable in question as it is still 1761.
subroutineA does some other things, then gets to subroutineC which is contained in another module that also uses the shared variables module. If I put a breakpoint at subroutineC, I can see in the watch window that the value of the variable in question still has 1761 as its value. As soon as I step into subroutineC, the variable in question gets reset to 0, and bad things happen in subroutineC. If, in the debugger, I simply step into subroutineC, then move the execution pointer to the return statement at the end of subroutineC, then step out of subroutineC, the value of the variable in question returns to what it should be - 1761.
I've been through several steps already to try to find an answer to this:
- At first, the variable was passed to subroutineC as a parameter and subroutineC used the same name as in the shared variable module - however - the compiler issued no errors or warnings about this. When I first noticed the problem, I changed the name of the variable in subroutineC. Same results.
- In subroutineC, I tried declaring the renamed variable as INTENT(IN), same results.
- Thinking that there may be some sort of illegal array access (even though I have detection of array out of bounds set in the compiler), I moved the parameter to the first parameter in subroutineC's signature. Same results.
- I then removed the variable from subroutineC's signature, and used the access granted to it via the use statement for the shared variables module. I still get the same results.
I am doing this elsewhere, so I do not understand why it is not working in this case. It is as if the module where subroutineC is is getting another instance of the shared variables module.
Any thoughts or ideas as to what the problem is and how to solve it?
Thanks in advance!