- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Assume that I have a module M, which CONTAINs a subroutine S. Assume that M declares a variable V; Assume that S also declared a variable V.
In this case, Fortran dictates that the local definition of V in S takes precedence over the definition of V in M. This is handled very well by the compiler of course; not so much by the human brain :) as it can get confusing.
I have two questions regarding this:
1.Is there a way to have the compiler emit a warning when a local declaration (in a contained subroutine) overrides a module declaration?
2. If not, is there a way to declare variables in a module to prevent them from being accessible to the contained subroutines?
If this is not possible now, maybe these could be suggestions for future versions of IVF?
Thanks,
Olivier
In this case, Fortran dictates that the local definition of V in S takes precedence over the definition of V in M. This is handled very well by the compiler of course; not so much by the human brain :) as it can get confusing.
I have two questions regarding this:
1.Is there a way to have the compiler emit a warning when a local declaration (in a contained subroutine) overrides a module declaration?
2. If not, is there a way to declare variables in a module to prevent them from being accessible to the contained subroutines?
If this is not possible now, maybe these could be suggestions for future versions of IVF?
Thanks,
Olivier
Link Copied
1 Reply
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
1) No.
2) No.
The problem we'd have with issuing a diagnostic for this is that the standard explicitly dictates this behavior and for many it would be what they want. So if we made the warning a default, we'd get complaints. If it wasn't a default, then most people would never see the warning even in cases where it was appropriate.
I do sympathize. The mistake can go in the opposite direction, by the way - failing to declare a local variable and having it pick up the module variable instead. I've been bitten by this (see Doctor Fortran in "Think, Thank, Thunk"), and again there's no way the compiler could have warn me about it.
What I would suggest is a bit of discipline in naming module variables - give them some special prefix that indicates their "global" status. You might even want to distinguish between public and private variables (private variables can still be accessed by contained procedures but not by users of the module.)
2) No.
The problem we'd have with issuing a diagnostic for this is that the standard explicitly dictates this behavior and for many it would be what they want. So if we made the warning a default, we'd get complaints. If it wasn't a default, then most people would never see the warning even in cases where it was appropriate.
I do sympathize. The mistake can go in the opposite direction, by the way - failing to declare a local variable and having it pick up the module variable instead. I've been bitten by this (see Doctor Fortran in "Think, Thank, Thunk"), and again there's no way the compiler could have warn me about it.
What I would suggest is a bit of discipline in naming module variables - give them some special prefix that indicates their "global" status. You might even want to distinguish between public and private variables (private variables can still be accessed by contained procedures but not by users of the module.)

Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page